|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-03-23 13:09 UTC] js at enradia dot com
Description: ------------ When trying to reassign $this (from session data for example) I get an error: Fatal error: Cannot re-assign $this in... Code used: $this = unserialize($data); This works in php 4. Perhaps this is a feature change but I could not find a reference to any alternatives so I am submitting a bug just in case. Thanks! Joshua Reproduce code: --------------- $this = unserialize($data); Expected result: ---------------- Assignment of session or serialized data to $this object Actual result: -------------- Fatal error: Cannot re-assign $this in... PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
Here is a potential solution. Where you would have reassigned $this, do something like this: $this->Object = new Whatever(); Or, in the case of unserializing session data $this->Session = unserialize($data); Now you have a choice. Your first option is to delegate every method that needs to be delegated. So, $this would need methods for every method in $Object. Each method would look something like: function nameOfFunction() { return $this->Object->nameOfFunction(); } The other option is to intercept all method calls, and then decide on the fly if they belong to $this or to $this->Object. If you have properties, I think you are going to have to intercept with __get() and __set(). You can read about overloading object functions with __get(), __set(), and __call() here: http://us2.php.net/manual/en/migration5.oop.php#migration5.oop.overload I chose the delegation model. If possible, I would recommend that. If you have properties to deal with, you will have to intercept the __get() and __set() calls and handle them appropriately.osCommerce 2.2-MS2 gets same error when open admin folder. Error in file includes/classes/upload.php. On Windows/IIS5/ISAPI. Resolwed by commenting: // self destruct // $this = null; Worked at PHP4 Good Luck!