Greetings,

 

This is a little difficult to explain. So, below is an example I will work
from. Forgive my ignorance here. I am a java developer using php4 and trying
to figure out a particular scenario.

 

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.

 

Is there a way to accomplish this behavior in php 4?

 

For example:

 

==== myscript.php ====

 

.

 

$myarr = array();

 

$myarr["valuea"]="a";

$myarr["valueb"]="b";

$myarr["valuec"]="c";

 

$myclass = new MyClass();

$myclass->addVal($myarr);

 

var_dump($myarr);

 

.

 

=======end ========

 

 

 

==== myclass.php ====

 

class MyClass {

 

function addVal($myarr){

  $myarr["valued"] = "d";

  var_dump($myarr);

}

 

}

=======end ========

 

 

Thanks,

Brandon

 

Reply via email to