How to set $this in PHP5

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I ran into this problem trying to run a PHP4 program in PHP5:

A class implements persistence by serializing itself and saving the string
to a file. In the constructor, the object restores itself by setting $this
to the result from unserialize(). In PHP4, this is legal. In PHP5 I get an
error. How do I fix this aside from manually copying the object properties?

Re: How to set $this in PHP5

Chung Leong wrote:
Quoted text here. Click to load it

If you don't want to copy the properties, the only thing you can do is
storing the unserialized object as a class property and use it from there.

Otherwise, you could use the reflectionObject class to simplify the task of
copying the properties:

$ro = new reflectionObject($obj);
foreach ($ro->getProperties() as $propObj) {
      $this-> = $obj->;


Site Timeline