ID: 28458 Updated by: [EMAIL PROTECTED] Reported By: chrispeery at cox dot net -Status: Open +Status: Feedback Bug Type: Session related Operating System: Red Hat Linux 2.4.9-e.12 PHP Version: 5.0.0RC2 New Comment:
Please try using this CVS snapshot: http://snaps.php.net/php5-STABLE-latest.tar.gz For Windows: http://snaps.php.net/win32/php5.0-win32-latest.zip Previous Comments: ------------------------------------------------------------------------ [2004-05-20 22:06:41] dharana at dharana dot net This is intended behaviour. Objects are passed by reference by default in php 5. ------------------------------------------------------------------------ [2004-05-20 19:09:21] chrispeery at cox dot net Description: ------------ The problem occurs when you store an object into the session and then try and create a local copy of that object. In PHP version 4.3.4 when you create the local copy of the object and modify it the object in the session does not change. However with PHP 5.0.0RC2 when you modify the local copy of the object it will also modify the object that is stored in the session. Is this the desired behavior for the newer version. Also one more thing to point out, if your working with any other datatype like array or strings stored in the session this does not happen. Reproduce code: --------------- <?php session_start(); echo("<br><br><hr>TEST SESSION WITH OBJECT<br>"); $my_object = (object) array('value_one'=>'1'); $_SESSION['TEST_OBJECT'] = $my_object; $local_object_copy = $_SESSION['TEST_OBJECT']; echo("SESSION BEFORE:<br>"); var_dump($_SESSION['TEST_OBJECT']); echo("<br><br>"); echo("LOCAL COPY BEFORE:<br>"); var_dump($local_object_copy); echo("<br><br>"); $local_object_copy->value_one = '2'; echo("SESSION AFTER:<br>"); var_dump($_SESSION['TEST_OBJECT']); echo("<br><br>"); echo("LOCAL COPY AFTER:<br>"); var_dump($local_object_copy); ?> Expected result: ---------------- I would expect for the local copy of the object to be modified and the object stored in the Session not to be modified. Unless of course I explicity set my local variable like so ($local_object_copy =& $_SESSION['TEST_OBJECT'];) Actual result: -------------- The actual result is that the object stored in the session has the exact same value as the local copy I created. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28458&edit=1