Jump to content

serializing objects - loses methods - the point being?


glenelkins

Recommended Posts

Hi

 

I know that serializing an object will lose the methods. But whats the point in that? What if we need the methods . Lets say the serialized string is sent from an external server where the calling function does not have access to the class file itself. then there is no way to use the methods?

As long as the unserialized object still has access to the class it was derived from you will have access to the methods associated with that object.

 

The point of serialisation is, in the context I've used it in before, for caching large objects that do not change much over time.

 

Please be aware however, that de-serialization is very slow.

 

Check out the article below for some interesting stuff with objects and serialization.

 

http://www.devshed.com/c/a/PHP/The-Basics-of-Serializing-Objects-in-PHP/1/

hi

 

of course i have to unserialize it. but that doesnt give access to any methods.

 

Lets take for example. On one server i have a script that returns an object of the following class:

 

class User {

    private $_username = 'John';

    public function getUsername() {

        // do something to the username here

       return $this->_username;

    }

}

 

 

The script that creates the object is called through CURL from another server, then unserializes the object

 

im left with the object , without the getUsername method and a private variable i cannot access

 

 

There must be a way around this!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.