Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:14:27+00:00 2026-06-10T18:14:27+00:00

I’m not getting how can serialize help me in writing efficient PHP application .

  • 0

I’m not getting how can serialize help me in writing efficient PHP application .

I am currently working on a stand-alone project on PHP where i have created a class to display a question feed which contains methods for throwing front-end HTMLs, and processing parts are also written in the same class.

Just for a example my outlined class is as follows

class QuestionFeed{
    protected $vars;

    public function throwHTML($filter_params){
        ........
    }

    public function InsertAnswers($answer_sanitized){
        .........
    }
}

And I have a page to display the front-part and a separate page for the insertion part. So naturally, I have to instantiate the class first at the display page and again at the processing page.
At this point, can serializing the object helps in any ways? And how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:14:29+00:00Added an answer on June 10, 2026 at 6:14 pm

    Serializing an object is useful when you need to save the state of an object for later use. For example, you may have a user object that keeps user preferences, etc. Since the web is stateless, you will loose that object with each request. However, if you were to say serialize that object and save it in a session variable, that object could be reconstructed by unserializing it, thus, saving you from having to reconstruct a new object you already had during the last request.

    On a side note: serializing and then unserializing an object will also accomplish a deep copy of an object where (clone) will only perform a shallow copy.

    Example of serialization

    <?php
    
    class User {
    
        private $name = "";
    
        public function __construct($name) {
            $this->name = $name;
        }
    
        public function getName() {
            return $this->name;
        }
    
        public function setName($name) {
            $this->name = $name;
        }
    
        /*
        public function __sleep() {
            print "sleep";
        }
    
        public function __wakeup() {
            print "wakeup";
        }
        */
    }
    
    $user = new User("Andrew Schools");
    $userSerialized = serialize($user); // usually you would save this in a session or DB
    $user2 = unserialize($userSerialized);
    
    echo $user->getName();
    echo "<br />";
    echo $user2->getName();
    echo "<br />";
    var_dump($user);
    var_dump($user2);
    
    
    
    ?>
    

    This should print out the following:

    Andrew Schools
    
    Andrew Schools
    
    class User#1 (1) {
      private $name =>
      string(14) "Andrew Schools"
    }
    class User#2 (1) {
      private $name =>
      string(14) "Andrew Schools"
    }
    

    So as you can see, I can restore my object to the way it was prior to serialization. Also, the __sleep() function is triggered before serialization begins so you can do any cleanup. And __wakeup is called after unserialization so that you can do some additional tasks after the object is restored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.