#41641 [Com]: Indirect Modification Notice due to modification using __set

From: Date: Sun, 25 Nov 2007 20:46:23 +0000
Subject: #41641 [Com]: Indirect Modification Notice due to modification using __set
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120048@lists.php.net to get a copy of this message
ID: 41641 Comment by: g42 at gmx dot net Reported By: asnyder at mddev dot com Status: Assigned Bug Type: Scripting Engine problem Operating System: Linux Fedora Core 4 PHP Version: 5.2.3 Assigned To: helly New Comment: brjann: well, you're right, it will work if you use "public function &__get(){...}". But that solution will not call __set at all (which is a problem in some cases). the following example won't throw a warning and will basically work: <?php error_reporting(E_ALL); class newclass { private $properties; public function &__get($key) { echo "get $key<br>"; return $this->properties[$key]; } public function __set($key, $val) { echo "set $key to $val<br>"; $this->properties[$key] = $val; } } $c = new newclass; $c->array['test'] = 'test'; ?> expected output: get array set array to test actual output: get array I understand that it's not possible to catch this modification because it's done via reference, so i won't write a bugreport... Although it's still a bit confusing... Previous Comments: ------------------------------------------------------------------------ [2007-09-27 20:16:19] brjann at gmail dot com It seems that declaring the getter as "public function &__get(){...}" does the trick. However, it took some googling to find. ------------------------------------------------------------------------ [2007-09-25 16:22:55] brjann at gmail dot com When 5.2.0 was released, several complaints about this issue were submitted (see http://bugs.php.net/bug.php?id=39449), and it was resolved. But now we're there again. Fact is that this seriously breaks wrapping functions that my project relies on, and I still don't understand the logic of modification of overloaded array properties not working is expected behaviour, while modification of non-array properties works. Will this be fixed? If not, why, and why was it then fixed after bug report 39449? Was it just so that me and others would keep on writing code that is now useless? ------------------------------------------------------------------------ [2007-08-22 14:49:30] jani@php.net Marcus, can you give an educated answer to this..? ------------------------------------------------------------------------ [2007-08-22 05:53:14] asnyder at mddev dot com First of all, I don't appreciate your snotty attitude. Second, if you actuallyread the post, you would realize this is not the same issue. In that post they were actually modifying a value, in my post, I'm simply using the __get, __set as magic methods in order to call a different function. This is VERY different. It's ok for the call to Set and not raise the notice. If you look at the functions there's nothing in danger of being modifed incorrectly. Please read before you post an incorrect response. I know its hard from that pedestool your on, but sometimes it's best to come down, and discuss things with other people. I would like to think myself as educated in the ways of PHP, and might consider fixing this myself, and submitting it to the repository. I was hoping to save myself the trouble, and let someone more experienced with the php internals work on it, but if you won't fix it, I will. ------------------------------------------------------------------------ [2007-08-17 20:12:26] vrana@php.net Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Thank you for your interest in PHP. Same as bug #38102. ------------------------------------------------------------------------ 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 http://bugs.php.net/41641 -- Edit this bug report at http://bugs.php.net/?id=41641&edit=1

« previous php.bugs (#120048) next »