From:             mira at st dot jyu dot fi
Operating system: Linux Mandrake 10.0
PHP version:      4.3.4
PHP Bug Type:     Class/Object related
Bug description:  serialize() combined with references and objects modifies $this

Description:
------------
See the attached script. The problem is reproduceable with PHP 4.3.4 on
Apache 2.0.48 (Apache and PHP versions that are distributed with Mandrake
10.0).

The problem seems to be caused by method setX(). If I replace that method
with
        function setX($x) {
                return $this->x = $x;
        }
or
        function &setX($x) {
                $this->x = $x;
                return $this->x;
        }
I get the expected end result. [Note that the former doesn't return the
reference so it isn't equivalent to original code.]

Also note that if I remove the first echo, the result of the second echo
is different so it seems that serialize($this) is modifying $this. It
might be that object's internal represenation is already trashed, though.


Reproduce code:
---------------
<pre><?php
class foo
{
        function test() {
                $this->setX("28");
                echo "this = ".serialize($this)."\n";
                echo "this->getX() = ".serialize($this->getX())."\n";
        }
        function &setX($x) {
                return $this->x = $x;
        }
        function &getX() {
                return $this->x;
        }
}
$foo =& new foo();
$foo->test();
?></pre>


Expected result:
----------------
this = O:3:"foo":1:{s:1:"x";s:2:"28";}
this->getX() = s:2:"28";


Actual result:
--------------
this = O:3:"foo":1:{s:1:"x";O:3:"foo":1:{s:1:"x";N;}}
this->getX() = O:3:"foo":1:{s:1:"x";O:3:"foo":1:{s:1:"x";R:2;}}


-- 
Edit bug report at http://bugs.php.net/?id=28359&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28359&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28359&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28359&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28359&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28359&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28359&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28359&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28359&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28359&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28359&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28359&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28359&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28359&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28359&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28359&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28359&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28359&r=float

Reply via email to