|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-05-20 22:06 UTC] dharana at dharana dot net
[2005-02-10 20:11 UTC] tony2001@php.net
[2005-02-18 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 07:00:01 2025 UTC |
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.