References
| From: | Dirk Schmidt | Date: | Fri, 13 Aug 1999 18:48:31 +0000 |
| Subject: | References | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-3401@lists.php.net to get a copy of this message | ||
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
3 var $Name;
4
5 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;