note 98761 deleted from language.references.arent by danbrown
| From: | danbrown@php.net | Date: | Tue, 06 Jul 2010 13:23:07 +0000 |
| Subject: | note 98761 deleted from language.references.arent by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170736@lists.php.net to get a copy of this message | ||
Note Submitter: davidsoutehr at gmail dot com
----
russrobinson, you are incorrect. Notice that in your code, line 18, you assign directly to the $var
reference, which in both PHP and C++ will indeed make $var and $bar point to the same instance of
the dog object. However, if you replace line 18 in your example with a reference assignment, eg
$var =& new Dog("gypsy");
the example will behave exactly as described in the documentation.
southerd@schroedinger:~/Desktop$ cat testRef.php
<?php
class Dog
{
var $Name;
function Dog($name)
{
$this->Name = $name;
}
function GetName()
{
return ($this->Name);
}
};
$bar = new Dog("Spot");
function foo(&$var)
{
$var =& new Dog("Gypsy");
}
foo($bar);
echo $bar->GetName()."\n";
echo "If that said 'Gypsy', then object references are really pointers\n";
?>
southerd@schroedinger:~/Desktop$ php testRef.php
Spot
If that said 'Gypsy', then object references are really pointers