note 97695 added to language.references.arent

From: Date: Mon, 03 May 2010 21:22:08 +0000
Subject: note 97695 added to language.references.arent
Groups: php.notes 
Request: Send a blank email to php-notes+get-168893@lists.php.net to get a copy of this message
The example shown is correct for scalars. However, in PHP5 the example does not cover objects, which behave the opposite of the way this documentation indicates. It is my view that object references in PHP5 are exactly like pointers in C++. This example code illustrates my point: <?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 "<p>".$bar->GetName(); echo "<p>"."If that said 'Gypsy', then object references are really pointers"; ?> And the output is: **** Gypsy If that said 'Gypsy', then object references are really pointers **** Therefore, corrected documentation should read (or similar): " Unless $bar is an object, there's no way to bind $bar in the calling scope to something else using the reference mechanism since $bar is not available in the function foo (it is represented by $var, but $var has only variable contents and not name-to-value binding in the calling symbol table). If $bar is an object, then you can change $bar in the calling scope using the reference mechanism inside a function. " ---- Server IP: 117.55.229.1 Probable Submitter: 121.219.3.204 ---- Manual Page -- http://www.php.net/manual/en/language.references.arent.php Edit -- https://master.php.net/note/edit/97695 Del: integrated -- https://master.php.net/note/delete/97695/integrated Del: useless -- https://master.php.net/note/delete/97695/useless Del: bad code -- https://master.php.net/note/delete/97695/bad+code Del: spam -- https://master.php.net/note/delete/97695/spam Del: non-english -- https://master.php.net/note/delete/97695/non-english Del: in docs -- https://master.php.net/note/delete/97695/in+docs Del: other reasons-- https://master.php.net/note/delete/97695 Reject -- https://master.php.net/note/reject/97695 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168893) next »