Hello,

I've upgraded from 5.1.1 to 5.1.2 and discovered the following unexpected difference. Best shown by example.

<?
   function getArray(&$arr)
   {
       $arr[] = 12;
   }

   getArray($p = array());
   print_r($p);
?>

In php 5.1.1, the $p is passed correctly as reference and so returns with the value 12 in its first element. I regard this as correct behaviour.
In php 5.1.2, the $p is passed by value. So on return, $p is still empty!
This can be fixed as follows:
   $p = array();
   getArray($p);



The following example works, as expected, in both 5.1.1 and 5.1.2.

<?
class A
{
       public $i = 9;
}


function doAmend(A &$a) // & not required because class instance passed by reference by default
{
       $a->i += 30;
}

       doAmend($b = new A);
print_r($b); // this prints the value of member i as 39 as expected.

?>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to