note 99531 rejected from language.references.arent by danbrown
| From: | danbrown@php.net | Date: | Mon, 23 Aug 2010 15:45:27 +0000 |
| Subject: | note 99531 rejected from language.references.arent by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171946@lists.php.net to get a copy of this message | ||
Note Submitter: northhero at gmail dot com
----
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