Bug #66961 [Opn->Ver]: get_object_vars() returns object references
| From: | yohgaki@php.net | Date: | Sun, 06 Jul 2014 01:50:28 +0000 |
| Subject: | Bug #66961 [Opn->Ver]: get_object_vars() returns object references | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186481@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66961&edit=1
ID: 66961
Updated by: yohgaki@php.net
Reported by: thomas dot stavang dot pedersen at gmail dot com
Summary: get_object_vars() returns object references
-Status: Open
+Status: Verified
Type: Bug
Package: Unknown/Other Function
Operating System: Linux, Fedora 19
PHP Version: 5.5.10
Block user comment: N
Private report: N
New Comment:
http://3v4l.org/H7h4N
It seems PHP does changes value while HHVM does not.
Previous Comments:
------------------------------------------------------------------------
[2014-03-26 14:30:16] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66961&edit=1