From:             phpbugs at thequod dot de
Operating system: Ubuntu Linux
PHP version:      5CVS-2007-03-15 (CVS)
PHP Bug Type:     Arrays related
Bug description:  Overloading: "Indirect modification" with "$this->foo[] = $x"

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 bug report at http://bugs.php.net/?id=40828&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=40828&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=40828&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=40828&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=40828&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=40828&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=40828&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=40828&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=40828&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=40828&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=40828&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=40828&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=40828&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=40828&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=40828&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=40828&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=40828&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=40828&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=40828&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=40828&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=40828&r=mysqlcfg

Reply via email to