How to say if a PHP variable is a reference variable

Possible duplicate:
Detecting if a PHP variable is a link / link

I am wondering if there is a function that will tell me if the variable is a reference variable. If there is no specific function, is there a way to determine if it is a reference variable?

+4
source share
4 answers

You can determine this using debug_zval_dump . See my answer for another question .

+1
source

From user examples, it seems that there is no direct way, but you will find a solution there.

0
source

You can use this function from one of the commenters in PHP documents. But afaik does not have a built-in function to check if var is a var reference.

0
source
 <?php $a = 1; $b =& $a; $c = 2; $d = 3; $e = array($a); function is_reference($var){ $val = $GLOBALS[$var]; $tmpArray = array(); /** * Add keys/values without reference */ foreach($GLOBALS as $k => $v){ if(!is_array($v)){ $tmpArray[$k] = $v; } } /** * Change value of rest variables */ foreach($GLOBALS as $k => $v){ if($k != 'GLOBALS' && $k != '_POST' && $k != '_GET' && $k != '_COOKIE' && $k != '_FILES' && $k != $var && !is_array($v) ){ usleep(1); $GLOBALS[$k] = md5(microtime()); } } $bool = $val != $GLOBALS[$var]; /** * Restore defaults values */ foreach($tmpArray as $k => $v){ $GLOBALS[$k] = $v; } return $bool; } var_dump(is_reference('a')); var_dump(is_reference('b')); var_dump(is_reference('c')); var_dump(is_reference('d')); ?> 

This is an example from the PHP documentation .

0
source

All Articles