Once I pass a variable inside a function as a reference, if I later access it, is it still a reference or..?
Example:
function one(){
$variables = array('zee', 'bee', 'kee');
$useLater =& $variables;
two($variables);
}
function two($reference){
foreach($reference as $variable){
echo 'reference or variable, that is the question...';
}
}
In function two(); are the variables here a reference to previously set $variables or a new element is created (in memory, I guess..)?
Plus, one more, is there a way to check if variable is passed by reference or not? (like: is_reference();)
A variable is only passed by reference (in current versions of PHP), if you explicitly pass it by reference using
&$foo.Equally, when declaring a variable to a new variable, such as
$foo = $bar, $foo will be a reference to $bar until the value changes. Then it is a new copy.There are lots of ways of detecting a reference here, maybe check some of them out. (Why you would need to do this is unknown, but still, it is there).
http://www.php.net/manual/en/language.references.spot.php