php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66961 get_object_vars() returns object references
Submitted: 2014-03-26 14:30 UTC Modified: 2014-07-06 01:50 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: thomas dot stavang dot pedersen at gmail dot com Assigned:
Status: Verified Package: Unknown/Other Function
PHP Version: 5.5.10 OS: Linux, Fedora 19
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-03-26 14:30 UTC] thomas dot stavang dot pedersen at gmail dot com
Description:
------------
get_object_vars() returns an array which can be manipulated as you would using a normal object. Manipulating the resulting array should not manipulate the object itself, but it does in this case.



Test script:
---------------
class Foo
{
  public $bar = null;
  public function __construct() {
    $this->bar = new DateTime(); // Now
    $this->far = &$this->bar;
  }
}
$foo= new Foo();
var_dump($foo);
$vars = get_object_vars($foo);
$vars['bar'] = new DateTime('2014-03-25');
var_dump($foo);


Expected result:
----------------
$foo->bar should not be altered, as we are only changing the get_object_vars() array, but it is.

Actual result:
--------------
$foo->bar (and $foo->far) gets a new value.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-06 01:50 UTC] yohgaki@php.net
-Status: Open +Status: Verified
 [2014-07-06 01:50 UTC] yohgaki@php.net
http://3v4l.org/H7h4N

It seems PHP does changes value while HHVM does not.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC