Professional Web Applications Themes

#40828 [NEW]: Overloading: "Indirect modification" with "$this->foo[] = $x" - PHP Bugs

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 ...

  1. #1

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

    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
    phpbugs Guest

  2. #2

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

    ID: 40828
    Updated by: 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:
     
    The code in my comment works perfectly fine.
     
    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
    tony2001@php.net Guest

  3. #3

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

    ID: 40828
    Updated by: net
    Reported By: phpbugs at thequod dot de
    Status: Bogus
    Bug Type: Arrays related
    Operating System: Ubuntu Linux
    PHP Version: 5CVS-2007-03-15 (CVS)
    New Comment:

    Please, if you have any other _questions_ - ask them on a support
    forum.


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-15 19:44:25] net
     
    The code in my comment works perfectly fine.
     
    No, it can't do your job for you. You have to do it in the __get()
    method.


    ------------------------------------------------------------------------

    [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
    tony2001@php.net Guest

  4. #4

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

    ID: 40828
    User updated by: phpbugs at thequod dot de
    Reported By: phpbugs at thequod dot de
    Status: Bogus
    Bug Type: Arrays related
    Operating System: Ubuntu Linux
    PHP Version: 5CVS-2007-03-15 (CVS)
    New Comment:
     
    >No, it can't do your job for you. You have to do it in the __get()[/ref]
    method.

    1. It also won't work with
    function &__get($name)
    {
    echo "__get() called.\n";
    $r = array();
    return $r;
    }
    2. It would not make sense to init any unknown/unhandled property
    as "array()" anyway
    3. Your comment works, if you remove the "(array)" typecast in
    &__get() - it will cause "Only variable references should be
    returned by reference" otherwise
    4. I'm not looking for support, but state that "$this->foo[]" is not
    supported in overloading - in contrast what you would expect

    Please note that this is different from bug 40823, where _any_
    property (which goes through __get()) gets handled as Foo::array!

    What I want to work is:
    Only handle some members as overloaded properties (e.g. $foo and
    $bar), but let all others work as intended - and that
    means "$A->foobar[]=" should work, just like "$foobar[]=" does.

    Please make sure you really understand what the problem IMHO is
    here!

    At least this should get closed as "Wont fix" and doented on
    http://php.net/manual/en/language.oop5.overloading.php.

    See also
    http://php.net/manual/en/language.oop5.overloading.php#73512


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-15 19:45:15] net

    Please, if you have any other _questions_ - ask them on a support
    forum.

    ------------------------------------------------------------------------

    [2007-03-15 19:44:25] net
     
    The code in my comment works perfectly fine.
     
    No, it can't do your job for you. You have to do it in the __get()
    method.


    ------------------------------------------------------------------------

    [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
    phpbugs Guest

  5. #5

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

    ID: 40828
    User updated by: phpbugs at thequod dot de
    Reported By: phpbugs at thequod dot de
    -Status: Bogus
    +Status: Open
    Bug Type: Arrays related
    Operating System: Ubuntu Linux
    PHP Version: 5CVS-2007-03-15 (CVS)
    New Comment:

    Re-opening.


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-16 14:57:28] phpbugs at thequod dot de
     
    >No, it can't do your job for you. You have to do it in the __get()[/ref]
    method.

    1. It also won't work with
    function &__get($name)
    {
    echo "__get() called.\n";
    $r = array();
    return $r;
    }
    2. It would not make sense to init any unknown/unhandled property
    as "array()" anyway
    3. Your comment works, if you remove the "(array)" typecast in
    &__get() - it will cause "Only variable references should be
    returned by reference" otherwise
    4. I'm not looking for support, but state that "$this->foo[]" is not
    supported in overloading - in contrast what you would expect

    Please note that this is different from bug 40823, where _any_
    property (which goes through __get()) gets handled as Foo::array!

    What I want to work is:
    Only handle some members as overloaded properties (e.g. $foo and
    $bar), but let all others work as intended - and that
    means "$A->foobar[]=" should work, just like "$foobar[]=" does.

    Please make sure you really understand what the problem IMHO is
    here!

    At least this should get closed as "Wont fix" and doented on
    http://php.net/manual/en/language.oop5.overloading.php.

    See also
    http://php.net/manual/en/language.oop5.overloading.php#73512

    ------------------------------------------------------------------------

    [2007-03-15 19:45:15] net

    Please, if you have any other _questions_ - ask them on a support
    forum.

    ------------------------------------------------------------------------

    [2007-03-15 19:44:25] net
     
    The code in my comment works perfectly fine.
     
    No, it can't do your job for you. You have to do it in the __get()
    method.


    ------------------------------------------------------------------------

    [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
    phpbugs Guest

  6. #6

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

    ID: 40828
    Updated by: 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:

    I've already explained everything, no need to repeat myself.


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-20 17:03:33] phpbugs at thequod dot de

    Re-opening.

    ------------------------------------------------------------------------

    [2007-03-16 14:57:28] phpbugs at thequod dot de
     
    >No, it can't do your job for you. You have to do it in the __get()[/ref]
    method.

    1. It also won't work with
    function &__get($name)
    {
    echo "__get() called.\n";
    $r = array();
    return $r;
    }
    2. It would not make sense to init any unknown/unhandled property
    as "array()" anyway
    3. Your comment works, if you remove the "(array)" typecast in
    &__get() - it will cause "Only variable references should be
    returned by reference" otherwise
    4. I'm not looking for support, but state that "$this->foo[]" is not
    supported in overloading - in contrast what you would expect

    Please note that this is different from bug 40823, where _any_
    property (which goes through __get()) gets handled as Foo::array!

    What I want to work is:
    Only handle some members as overloaded properties (e.g. $foo and
    $bar), but let all others work as intended - and that
    means "$A->foobar[]=" should work, just like "$foobar[]=" does.

    Please make sure you really understand what the problem IMHO is
    here!

    At least this should get closed as "Wont fix" and doented on
    http://php.net/manual/en/language.oop5.overloading.php.

    See also
    http://php.net/manual/en/language.oop5.overloading.php#73512

    ------------------------------------------------------------------------

    [2007-03-15 19:45:15] net

    Please, if you have any other _questions_ - ask them on a support
    forum.

    ------------------------------------------------------------------------

    [2007-03-15 19:44:25] net
     
    The code in my comment works perfectly fine.
     
    No, it can't do your job for you. You have to do it in the __get()
    method.


    ------------------------------------------------------------------------

    [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
    tony2001@php.net Guest

Similar Threads

  1. Replies: 1
    Last Post: April 24th, 01:27 PM
  2. #39775 [NEW]: "Indirect modification ..." message is not shown
    By toomuchphp-phpbugs at yahoo dot com in forum PHP Bugs
    Replies: 2
    Last Post: December 8th, 05:46 PM
  3. CFINPUT type="radio" w/ "value" requires "label"
    By Iceborer in forum Macromedia ColdFusion
    Replies: 2
    Last Post: February 21st, 06:16 PM
  4. #26162 [NEW]: $a="0abcdefg";if ($a==0) echo "OK"; result is "OK" ?!
    By zhuminglun at yahoo dot com dot cn in forum PHP Development
    Replies: 0
    Last Post: November 7th, 12:04 PM
  5. "Start" "Program" "Menu" list is empty
    By Pete in forum Windows XP/2000/ME
    Replies: 2
    Last Post: July 10th, 10:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139