|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-03-16 13:29 UTC] mk at peytz dot dk
Description: ------------ When setting variable variable values on a instance of a class with an overloading __set function changing another instance variable goes wrong. (I'm reporting it for version 5.0.3 because the current cvs snapshot would not compile.) Reproduce code: --------------- http://dev.peytz.dk/~mk/setter.php <?php class Setter { private $_fields = array(); // the data fields private $_changedFields = array(); // list of changed fields function __set($name, $value) { // set value $this->_fields[$name] = $value; // add to list of changed fields $this->_changedFields[] = $name; } } $foo = new Setter; $foo->a = 1; $var = "b"; $foo->$var = 2; var_export($foo); ?> Expected result: ---------------- class Setter { private $_fields = array ( 'a' => 1, 'b' => 2, ); private $_changedFields = array ( 0 => 'a', 1 => 'b', ); } Actual result: -------------- class Setter { private $_fields = array ( 'a' => 1, 'b' => 2, ); private $_changedFields = array ( 0 => 'a', 1 => '???', ); } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 01:00:01 2025 UTC |
Changed the var_export() -> var_dump() and got this with latest CVS: object(Setter)#1 (2) { ["_fields:private"]=> array(2) { ["a"]=> int(1) ["b"]=> int(2) } ["_changedFields:private"]=> array(2) { [0]=> string(1) "a" [1]=> &UNKNOWN:0 } }