* 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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to