note 99531 added to language.references.arent

From: Date: Mon, 23 Aug 2010 07:21:16 +0000
Subject: note 99531 added to language.references.arent
Groups: php.notes 
Request: Send a blank email to php-notes+get-171930@lists.php.net to get a copy of this message
It looks the example is not so "correct" now. If we remove the '&' mark from foo() function and pass a object type varible to it, reference will act just like pointer. On the contrary with the '&' it acts like what the example said. class TestClass { public $value; function __construct($val) { $this->value = $val; } } $baz = new TestClass('baz'); function foo(&$var) { $var = $GLOBALS["baz"]; } foo($bar); $bar->value = 'bar'; echo "<br>".$baz->value; echo "<br>".$bar->value; yeild bar bar class TestClass { public $value; function __construct($val) { $this->value = $val; } } $baz = new TestClass('baz'); function foo(&$var) { $var = &$GLOBALS["baz"]; } foo($bar); $bar->value = 'bar'; echo "<br>".$baz->value; echo "<br>".$bar->value; yeild baz bar ---- Server IP: 61.195.146.164 Probable Submitter: 126.112.211.154 ---- Manual Page -- http://www.php.net/manual/en/language.references.arent.php Edit -- https://master.php.net/note/edit/99531 Del: integrated -- https://master.php.net/note/delete/99531/integrated Del: useless -- https://master.php.net/note/delete/99531/useless Del: bad code -- https://master.php.net/note/delete/99531/bad+code Del: spam -- https://master.php.net/note/delete/99531/spam Del: non-english -- https://master.php.net/note/delete/99531/non-english Del: in docs -- https://master.php.net/note/delete/99531/in+docs Del: other reasons-- https://master.php.net/note/delete/99531 Reject -- https://master.php.net/note/reject/99531 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171930) next »