note 95369 added to language.oop5.overloading
| From: | meagar at gmail dot com | Date: | Tue, 29 Dec 2009 16:22:21 +0000 |
| Subject: | note 95369 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164437@lists.php.net to get a copy of this message | ||
Franz: It doesn't say assignment chaining doesn't work, it simply says that the return
value of __set is ignored. So this works fine:
<?php
$x = $obj->field = 7;
// $x == 7, $obj->field == 7
?>
On the other hand, this won't work as you (the author of class Test) expect, but will continue
to behave as users of class Test expect:
<?php
class Test {
function __set($field, $value) {
return $this->$field = "foo";
}
}
$test = new Test();
$x = $test->field = 7;
// $x == 7, $test->field == "foo"
?>
This is generally a good thing; altering the behaviour of something as fundamental as assignment
chaining is never a good idea.
----
Server IP: 66.207.199.35
Probable Submitter: 216.240.7.39
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/95369
Del: integrated -- https://master.php.net/note/delete/95369/integrated
Del: useless -- https://master.php.net/note/delete/95369/useless
Del: bad code -- https://master.php.net/note/delete/95369/bad+code
Del: spam -- https://master.php.net/note/delete/95369/spam
Del: non-english -- https://master.php.net/note/delete/95369/non-english
Del: in docs -- https://master.php.net/note/delete/95369/in+docs
Del: other reasons-- https://master.php.net/note/delete/95369
Reject -- https://master.php.net/note/reject/95369
Search -- https://master.php.net/manage/user-notes.php