|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-12-01 19:36 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 19:00:01 2025 UTC |
Description: ------------ When trying to access a magically returned (via __get()) property of a class, only an E_NOTICE is raised. While a function like array_pop will return a value (without modifying the overloaded property), some other operations will have less predictable results, such as array access via the "[]" syntax. Because a lot of distributions ship with a "$something | ~E_NOTICE" level of error reporting, and the "black box" ideas of object oriented programming (a developer trying to push an element onto a member array in an API class, for instance), this could be a very hard circumstance to debug. Furthermore, any case I can think of where this notice will be raised will never perform as expected, it will force the developer to re-engineer his solution. Because any case where this error would be raised will force a rewrite, I think that this circumstance should raise a fatal error instead. The fix is trivial enough that I did not attach a patch, but would be glad to in the future, if necessary. Reproduce code: --------------- <?php class foo { private $bar = array('1', '2', '3'); public function __get($var) { return $this->$var; } } $inst = new foo(); var_dump(array_pop($inst->bar)); Expected result: ---------------- PHP Fatal Error: Indirect modification of overloaded property foo::$bar has no effect in /home/blahblah/test.php on line 10 Actual result: -------------- PHP Notice: Indirect modification of overloaded property foo::$bar has no effect in /home/blahblah/test.php on line 10