Bug #66961 [NEW]: get_object_vars() returns object references

From: Date: Wed, 26 Mar 2014 14:30:17 +0000
Subject: Bug #66961 [NEW]: get_object_vars() returns object references
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184901@lists.php.net to get a copy of this message
From:             thomas dot stavang dot pedersen at gmail dot com
Operating system: Linux, Fedora 19
PHP version:      5.5.10
Package:          Unknown/Other Function
Bug Type:         Bug
Bug description:get_object_vars() returns object references

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 bug report at https://bugs.php.net/bug.php?id=66961&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=66961&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=66961&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=66961&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=66961&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=66961&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=66961&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=66961&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=66961&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=66961&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=66961&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=66961&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=66961&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=66961&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66961&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=66961&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=66961&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=66961&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66961&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=66961&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=66961&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#184901) next »