You can pass variable to function by reference, so that function could modify its arguments. The syntax is as follows:
<?php
function foo (& $var )
{
$var ++;
}
$a = 5 ;
foo ( $a );
// $a is 6 here
?> The following things can be passed by reference:
Reference, returned from a function, i.e.:
<?php
function & bar ()
{
$a = 5 ;
return $a ;
}
foo ( bar ());
?> Any other expression should not be passed by reference, as the result is undefined. For example, the following examples of passing by reference are invalid:
<?php
function bar () // Note the missing &
{
$a = 5 ;
return $a ;
}
foo ( bar ()); // Produces fatal error since PHP 5.0.5
foo ( $a = 5 ); // Expression, not variable
foo ( 5 ); // Produces fatal error
?> © 2005-2008 BlaBla.cn 版权所有