|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28458 Problem storing objects in Session
Submitted: 2004-05-20 19:09 UTC Modified: 2005-02-18 01:00 UTC
Avg. Score:2.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: chrispeery at cox dot net Assigned:
Status: No Feedback Package: Session related
PHP Version: 5.0.0RC2 OS: Red Hat Linux 2.4.9-e.12
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-05-20 19:09 UTC] chrispeery at cox dot net
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:
    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>");
    echo("LOCAL COPY BEFORE:<br>");

    $local_object_copy->value_one = '2';

    echo("SESSION AFTER:<br>");
    echo("LOCAL COPY AFTER:<br>");

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 =& 

Actual result:
The actual result is that the object stored in the 
session has the exact same value as the local copy I 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-20 22:06 UTC] dharana at dharana dot net
This is intended behaviour. Objects are passed by reference by default in php 5.
 [2005-02-18 01:00 UTC] php-bugs at lists dot php dot net
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".
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Jun 06 02:03:40 2023 UTC