How check memory location of variable in php?
Thanks
global variables are stored in the $GLOBALS associative array. It will print "global" and then "local".
memory_get_usage() — Returns the amount of memory allocated to PHP.
So, a variable is a named location in main memory that has three characteristics: a name, a content, and a memory address. How the compiler interprets a variable's name - either its address its contents - is determined by where the name appears in a given statement.
What are references in PHP? In PHP, references are “aliases” that allow two different variables to read and write a single value.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With