[Sussex] PHP4 - pointers and updates to a class
sparkeh at btinternet.com
sparkeh at btinternet.com
Thu Mar 24 21:39:03 UTC 2005
> function fred(&$var) {...
>
> Note the & (ampersand) in the formal parameter.
>
> You can also assign by reference:
>
> $x = 10;
> $y = &$x;
Also watch out for quirks such as that found when
using foreach:
$ar = array();
$x = 10;
$y = &$x;
$ar[] =& $x;
$ar[] =& $y;
foreach($ar as $k=>$v)
{
// At this point:
// $ar[$k] refers to the original item
// $v is a *copy* of the original item
}
-Mark
More information about the Sussex
mailing list