How check memory location of variable in php?

If you need to know if $varA is a reference to $varB, then you're out of luck: the PHP innards does not present this information to the developer.

However, you can extract some information about references by parsing the output from var_dump or debug_zval_dump(). Read the relevant manual sections, and see this question for some details.

And have a ready of this (PDF) article by Derick Rethans on references in PHP.

Watch out for the refcount when using debug_zval_dump() because the function always creates an additional reference within itself, incrementing the value by 1


If you need to know if a variable is a reference to another, then debug_zval_dump() is the only option.


To test if one variable is a reference to another you can do the following:

function is_ref_to(&$a, &$b)
{
    $t = $a;
    if($r=($b===($a=1))){ $r = ($b===($a=0)); }
    $a = $t;
    return $r;
}

Tags:

Php