note 83456 added to language.oop5.overloading

From: Date: Tue, 27 May 2008 09:01:29 +0000
Subject: note 83456 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-139839@lists.php.net to get a copy of this message
Expanding in part on what Hayley Watson said (5 Feb 2008) regarding $a=$b=$c: My first impression was that <?php $a=$foo->var=$c; ?> would assign $c to $foo->var (by using __set) and the *return value* of __set would be assigned to $a - like what happens in other languages. Perhaps the default (if __set returns void/null) would be $c. This is not the case. The code above is equivalent to <?php $foo->var=$c; $a=$c; ?>. Regardless of what __set returns, $a will always have the value of $c. <?php class Foo { public function __set($name,$value) { static $var; $var=$value; // return "abc"; // comment, uncomment at will } } $f=new Foo(); $g=($f->var="value"); echo $g; // $g is always "value", even if the return above is uncommented ?> ---- Server IP: 69.147.83.197 Probable Submitter: 75.172.103.166 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/83456 Del: integrated -- https://master.php.net/note/delete/83456/integrated Del: useless -- https://master.php.net/note/delete/83456/useless Del: bad code -- https://master.php.net/note/delete/83456/bad+code Del: spam -- https://master.php.net/note/delete/83456/spam Del: non-english -- https://master.php.net/note/delete/83456/non-english Del: in docs -- https://master.php.net/note/delete/83456/in+docs Del: other reasons-- https://master.php.net/note/delete/83456 Reject -- https://master.php.net/note/reject/83456 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139839) next »