|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-07 16:27 UTC] stephen dot cuppett at webmastersinc dot net
Description: ------------ Also documented in: http://pear.php.net/bugs/bug.php?id=11775 There appears to be a regression as to Bug #39449: http://bugs.php.net/bug.php?id=39449 On 5.2.4RC1, I'm getting the immutable overloaded properties problem with DB_DataObject and in the simple test below. Also bugs: 41116, 40828, 40823, 39990 Reproduce code: --------------- <?php class MyObj { private $map; public function __construct() { $this->map = array(); } public function __set($vn, $value) { $this->map[$vn] = $value; } public function __get($vn) { return $this->map[$vn]; } } $myvar = new MyObj(); $myvar->test_var = array(); $myvar->test_var['tester'] = 3; $myvar->test_var['tester2'] = 5; var_dump($myvar->test_var); ?> Expected result: ---------------- C:\temp\dataobject_test>php simpletest.php array(2) { ["tester"]=> int(3) ["tester2"]=> int(5) } Actual result: -------------- C:\temp\dataobject_test>php simpletest.php PHP Notice: Indirect modification of overloaded property MyObj::$test_var has no effect in C:\temp\dataobject_test\simpletest.php on line 16 Notice: Indirect modification of overloaded property MyObj::$test_var has no effect in C:\temp\dataobject_test\simpletest.php on line 16 PHP Notice: Indirect modification of overloaded property MyObj::$test_var has no effect in C:\temp\dataobject_test\simpletest.php on line 17 Notice: Indirect modification of overloaded property MyObj::$test_var has no effect in C:\temp\dataobject_test\simpletest.php on line 17 array(0) { } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 21:00:01 2025 UTC |
It should be noted that the supposed congruent case works: <?php class MyObj { public $test_var; } $myvar = new MyObj(); $myvar->test_var = array(); $myvar->test_var['tester'] = 3; $myvar->test_var['tester2'] = 5; var_dump($myvar->test_var); ?> C:\temp\dataobject_test>php simpletest.php array(2) { ["tester"]=> int(3) ["tester2"]=> int(5) }Indirect modification is not allowed because you return value from __get() by value. You should see corresponding warnings. To get that you like you should just return from get by reference. public function &__get($vn) { return $this->map[$vn]; }