#40828 [Opn->Bgs]: Overloading: "Indirect modification" with "$this->foo[] = $x"

From: Date: Thu, 15 Mar 2007 19:44:25 +0000
Subject: #40828 [Opn->Bgs]: Overloading: "Indirect modification" with "$this->foo[] = $x"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-110408@lists.php.net to get a copy of this message
ID: 40828 Updated by: tony2001@php.net Reported By: phpbugs at thequod dot de -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: Ubuntu Linux PHP Version: 5CVS-2007-03-15 (CVS) New Comment: >as Tony stated in http://bugs.php.net/bug.php?id=40823 >(the code in his comment does not work (anymore?)). The code in my comment works perfectly fine. >Can't PHP internally do "$this->test = array()"? No, it can't do your job for you. You have to do it in the __get() method. Previous Comments: ------------------------------------------------------------------------ [2007-03-15 19:35:49] phpbugs at thequod dot de Description: ------------ If a member of an object is not defined and "gets initialized" by PHP after/during the overloading process, a notice ("Indirect modification of overloaded property") gets triggered when PHP has to initialize it as an array type. It makes no difference, if __get() returns by reference instead (a ref to a null value), as Tony stated in http://bugs.php.net/bug.php?id=40823 (the code in his comment does not work (anymore?)). Background: we have a base class "Plugin" in our project and it uses __get() for some properties and returns null otherwise. Now, if some user-created plugin does $this->foo[] = 'bar' it will create this notice - which is quite confusing (if the derived plugin does not "init" $foo with "var $foo"). Can't PHP internally do "$this->test = array()"? (This may likely be a dupe of http://bugs.php.net/bug.php?id=39337 - but that one got quite confusing, so this one here may become a "reference bogus bug" for this issue at least.) Reproduce code: --------------- <?php class A { function __get($name) { echo "__get() called.\n"; } function A() { $this->test[] = 'foo'; } } $A = new A(); ?> Expected result: ---------------- __get() called. Actual result: -------------- __get() called. Notice: Indirect modification of overloaded property A::$test has no effect in foo.php on line 12 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40828&edit=1

« previous php.bugs (#110408) next »