Re: var references question

From: Date: Sun, 19 Sep 2004 15:04:25 +0000
Subject: Re: var references question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-197185@lists.php.net to get a copy of this message
* Thus wrote Brandon Goodin: > Greetings, > > > In the following example when I run the myscript.php I pass the $myarr into > the addVal function of the MyClass class. The var_dump in the addVal > function appropriately displays all of the elements of the array a,b,c and > d. However, the var_dump that is done in the script immediately following > the addVal method call displays only elements a,b and c with NO d. From what > I can see, php does not retain the same reference to the array object when > it passes it into the function. It appears that it clones the array and > retains only the changes within the scope of the function. In java I am used > to creating an array and passing it into a method which accomplishes > operations against the array. The passed in array is also modified because > it is a reference to the same array object. > PHP pass by value by default, you want to pass by reference, see: http://php.net/functions.arguments.php Curt -- The above comments may offend you. flame at will.

« previous php.general (#197185) next »