note 95369 deleted from language.oop5.overloading by thiago
| From: | thiago@php.net | Date: | Tue, 29 Dec 2009 16:30:13 +0000 |
| Subject: | note 95369 deleted from language.oop5.overloading by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164438@lists.php.net to get a copy of this message | ||
Note Submitter: meagar at gmail dot com
----
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.