#28458 [Fbk->NoF]: Problem storing objects in Session
| From: | php-bugs at lists dot php dot net | Date: | Fri, 18 Feb 2005 00:00:08 +0000 |
| Subject: | #28458 [Fbk->NoF]: Problem storing objects in Session | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-74251@lists.php.net to get a copy of this message | ||
ID: 28458
Updated by: php-bugs@lists.php.net
Reported By: chrispeery at cox dot net
-Status: Feedback
+Status: No Feedback
Bug Type: Session related
Operating System: Red Hat Linux 2.4.9-e.12
PHP Version: 5.0.0RC2
New Comment:
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
Previous Comments:
------------------------------------------------------------------------
[2005-02-10 20:11:21] tony2001@php.net
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
------------------------------------------------------------------------
[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