#38102 [Bgs->Opn]: Overloading __get()/__set() should explicitly state it is return-by-value

From: Date: Tue, 15 Aug 2006 07:22:54 +0000
Subject: #38102 [Bgs->Opn]: Overloading __get()/__set() should explicitly state it is return-by-value
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969373779@lists.php.net to get a copy of this message
ID: 38102 User updated by: frode at coretrek dot com -Summary: Assigning and updating array through __get()/__set() no longer works in 5.2-snap Reported By: frode at coretrek dot com -Status: Bogus +Status: Open -Bug Type: Scripting Engine problem +Bug Type: Documentation problem Operating System: Linux PHP Version: 5CVS-2006-07-14 (snap) New Comment: Thank you for your quick and consise answer. Yet again, I re-open this bug because I now think this is a documentation issue. I looked through the documentation on overloading (http://www.php.net/manual/en/language.oop5.overloading.php) and could not find any mention of return-by-value and return-by-reference. I think it would be very helpful to add a note to the manual stating something about __get()/__set() only works by-value. Also, this means there is no way to make a generic "shadow"/"call-through"/"wrapper" class for a class that exposes public non-object members, which is a shame (should I open a feature request bug for this?). This should perhaps also be noted in the manual, along with __call() also returning by-value? For reference, old bug summary was: Assigning and updating array through __get()/__set() no longer works in 5.2-snap Previous Comments: ------------------------------------------------------------------------ [2006-08-14 10:53:48] tony2001@php.net Because __get() returns variables by value, not by reference. It's identical to this code: <?php $var = 1; intval($var) = 5; //you wouldn't expect it to work, would you? ?> ------------------------------------------------------------------------ [2006-08-14 10:47:23] frode at coretrek dot com I'm taking the liberty to re-open the bug, since there has been no explanation for why 5.2 breaks code that works in 5.1.4. Thanks in advance to anyone that can clarify up this issue. ------------------------------------------------------------------------ [2006-07-14 10:05:17] frode at coretrek dot com Yes, I did run php5.2-200607140630. The error message you pasted is identical with the one I entered in 'actual results' in the original submission of this bug. Is this is a planned language change for PHP 5.2? Because the code runs with no errors in PHP 5.1.4. ------------------------------------------------------------------------ [2006-07-14 09:37:41] tony2001@php.net Did you REALLY try the latest snapshot? This is what I get with your code: Fatal error: Cannot use array returned from Class1::__get('property') in write context ... And this is well expected. ------------------------------------------------------------------------ [2006-07-14 09:12:20] frode at coretrek dot com Old summary was for an old bug report and was incorrectly autofilled by firefox :( ------------------------------------------------------------------------ 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/38102 -- Edit this bug report at http://bugs.php.net/?id=38102&edit=1

« previous php.doc (#969373779) next »