Re: [PHP4BETA] References
| From: | Zeev Suraski | Date: | Fri, 13 Aug 1999 19:49:56 +0000 |
| Subject: | Re: [PHP4BETA] References | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3402@lists.php.net to get a copy of this message | ||
You're a bit out of luck:
1. There is no way to return references from functions.
2. You can't tell foreach() to have the variable be a reference to the actual element - it's always a copy.
Zeev
At 20:48 13/08/99 , Dirk Schmidt wrote:
Hello List, I have a Problem with References. The following Example outputs: modified one one I have an Array of Objects ($aObjects). I assign an Object of type one to this array (Line 15) I assign this Object in different ways to other objects (Line 16 - 18). I modify a variable of this object (Line 20) and echo the variable 'Name' of all Objects. Problem: obj2 and obj3 are not modified. How can i return the return value of a function as a Reference value (Line 17) and how can i get the foreach-value as a reference (Line 18); thanks, Dirk 1 class one { 2-- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il3 var $Name;45 function one ($str){ 6 $this->Name = $str; 7 }8 } 9 10 function getObject ($i){11 global $aObjects; 12 return $aObjects[$i];13 } 14 $aObjects = array(); 15 $aObjects[] = new one("one"); 16 $obj1 = &$aObjects[0]; 17 $obj2 = getObject(0); 18 foreach($aObjects as $obj) $obj3 = &$obj; 19 20 $obj1->Name = "modified"; 21 22 echo "<BR>" . $obj1->Name; 23 echo "<BR>" . $obj2->Name; 24 echo "<BR>" . $obj3->Name; -- PHP 4 Beta