note 98761 added to language.references.arent
| From: | davidsoutehr at gmail dot com | Date: | Mon, 05 Jul 2010 21:43:26 +0000 |
| Subject: | note 98761 added to language.references.arent | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170723@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 192.234.222.10
----
Manual Page -- http://www.php.net/manual/en/language.references.arent.php
Edit -- https://master.php.net/note/edit/98761
Del: integrated -- https://master.php.net/note/delete/98761/integrated
Del: useless -- https://master.php.net/note/delete/98761/useless
Del: bad code -- https://master.php.net/note/delete/98761/bad+code
Del: spam -- https://master.php.net/note/delete/98761/spam
Del: non-english -- https://master.php.net/note/delete/98761/non-english
Del: in docs -- https://master.php.net/note/delete/98761/in+docs
Del: other reasons-- https://master.php.net/note/delete/98761
Reject -- https://master.php.net/note/reject/98761
Search -- https://master.php.net/manage/user-notes.php