Edit report at https://bugs.php.net/bug.php?id=52441&edit=1
ID: 52441 Comment by: jochen at menhir dot com Reported by: bastard dot internets at gmail dot com Summary: Arrays misbehaving with __set() and __get() Status: Open Type: Bug Package: Class/Object related Operating System: WIN PHP Version: 5.3.3 and 5.3.2 Block user comment: N Private report: N New Comment: I have this bug too and there is not anything I can do about how ->property[0] = value is been done. What is the status on this for now? Previous Comments: ------------------------------------------------------------------------ [2010-11-12 20:15:26] bastard dot internets at gmail dot com | Could you elaborate your second point? I couldn't understand that one. When setting any private property from outside the object, you would normally expect to get a fatal "Cannot access private property" error. However for private properties that are arrays, the line "$a->test_array[] = 'asdf'", where for all intents and purposes you are modifying a private property, just results in an odd notice. | Concerning all the other ones: Our sixth point is the solution. This is expected behavior. To modify an array property it must be returned by reference. There already have been several bugs on this topic and yet another one won't change anything ;) The problem with this solution ("&__get()") is that get() must always be defined to return by reference. And, all other private/protected properties will have to be returned by reference as well (though I can't think of where this would be a serious problem off the top of my head). The manual should at least be updated somewhere to mention that changes made to private/protected array properties from outside the object are routed through get(), not set(), and that the get() function must be defined to return the array property by reference. Either that or have get() magically return array properties by reference by default..? ------------------------------------------------------------------------ [2010-10-03 18:57:49] + at ni-po dot com Could you elaborate your second point? I couldn't understand that one. Concerning all the other ones: Our sixth point is the solution. This is expected behavior. To modify an array property it must be returned by reference. There already have been several bugs on this topic and yet another one won't change anything ;) ------------------------------------------------------------------------ [2010-07-26 01:50:34] bastard dot internets at gmail dot com PHP Version: These bugs are found in 5.3.3 and 5.3.2. Unknown status in 5.2. ------------------------------------------------------------------------ [2010-07-26 01:39:17] bastard dot internets at gmail dot com Der, that last comment was meant to be "Amendment to Result #3". Ignore that auto-linked reference to "bug #3" ------------------------------------------------------------------------ [2010-07-26 01:36:21] bastard dot internets at gmail dot com Amendment to bug #3: __set() is bypassed completely, and new arrays can be freely created within objects if not already protected or private. Only if directly setting the array itself (ie "$a->test_array = array();") will __set() be called. But not when doing something like "a$->test_array[] = 'asdf';" ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=52441 -- Edit this bug report at https://bugs.php.net/bug.php?id=52441&edit=1