From: chrispeery at cox dot net
Operating system: Red Hat Linux 2.4.9-e.12
PHP version: 5.0.0RC2
PHP Bug Type: Session related
Bug description: Problem storing objects in Session
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 bug report at http://bugs.php.net/?id=28458&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28458&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28458&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28458&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28458&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28458&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28458&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28458&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28458&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28458&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28458&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28458&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28458&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28458&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28458&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28458&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28458&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28458&r=float