|  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: 2017-10-29 08:51 UTC
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: Not a bug Package: Unknown/Other Function
PHP Version: 5.5.10 OS: Linux, Fedora 19
Private report: No CVE-ID: None
 [2014-03-26 14:30 UTC] thomas dot stavang dot pedersen at gmail dot com
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();
$vars = get_object_vars($foo);
$vars['bar'] = new DateTime('2014-03-25');

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-06 01:50 UTC]
-Status: Open +Status: Verified
 [2014-07-06 01:50 UTC]

It seems PHP does changes value while HHVM does not.
 [2017-10-29 08:51 UTC]
-Status: Verified +Status: Not a bug
 [2017-10-29 08:51 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

this behavior is expected, it's how reference works in PHP.

the problem here is not related to `get_object_vars()`. it's caused by `$this->far = &$this->bar;`. this will make both `->far` and `->bar` referenced. You can see there is an `&` before `object` in the `var_dump` output.

similar results can be found when you use array (see
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Feb 25 00:01:23 2021 UTC