note 97879 added to function.call-user-func

From: Date: Thu, 13 May 2010 15:49:35 +0000
Subject: note 97879 added to function.call-user-func
Groups: php.notes 
Request: Send a blank email to php-notes+get-169218@lists.php.net to get a copy of this message
Actually, when calling a static method of some class, the params are sent by reference: <?php class Foo { private $x = 0; public function getX(){ return $this->x; } public function setX($val){ $this->x = $val; } } class Bar { static function incStatic(Foo $f){ $f->setX($f->getX()+1); global $foo; if($f === $foo) echo '<span style="color: blue">' . __METHOD__ . '() objects are equal</span><br />'; else echo '<span style="color: red">' . __METHOD__ . '() objects are not equal</span><br />'; } public function incNonStatic(Foo $f){ $f->setX($f->getX()+1); if($f === $foo) echo '<span style="color: blue">' . __METHOD__ . '() objects are equal</span><br />'; else echo '<span style="color: red">' . __METHOD__ . '() objects are not equal</span><br />'; } } function inc(Foo $f){ $f->setX($f->getX()+1); if($f === $foo) echo '<span style="color: blue">' . __FUNCTION__ . '() objects are equal</span><br />'; else echo '<span style="color: red">' . __FUNCTION__ . '() objects are not equal</span><br />'; } $foo = new Foo; $bar = new Bar; call_user_func('inc', $foo); call_user_func('Bar::incStatic', $foo); call_user_func(array($bar, 'incNonStatic'), $foo); ?> The results on PHP 5.2.6 (macosx 10.5): inc() objects are not equal Bar::incStatic() objects are equal Bar::incNonStatic() objects are not equal Hope it helps sombody. ---- Server IP: 69.147.83.197 Probable Submitter: 82.76.132.251 ---- Manual Page -- http://www.php.net/manual/en/function.call-user-func.php Edit -- https://master.php.net/note/edit/97879 Del: integrated -- https://master.php.net/note/delete/97879/integrated Del: useless -- https://master.php.net/note/delete/97879/useless Del: bad code -- https://master.php.net/note/delete/97879/bad+code Del: spam -- https://master.php.net/note/delete/97879/spam Del: non-english -- https://master.php.net/note/delete/97879/non-english Del: in docs -- https://master.php.net/note/delete/97879/in+docs Del: other reasons-- https://master.php.net/note/delete/97879 Reject -- https://master.php.net/note/reject/97879 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169218) next »