Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How check memory location of variable in php?

Tags:

php

How check memory location of variable in php?

Thanks

like image 997
Ben Avatar asked Mar 01 '11 10:03

Ben


People also ask

Where are variables stored in PHP?

global variables are stored in the $GLOBALS associative array. It will print "global" and then "local".

Which function is used to detect how much memory the variable uses?

memory_get_usage() — Returns the amount of memory allocated to PHP.

What are variables memory locations?

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?

What are references in PHP? In PHP, references are “aliases” that allow two different variables to read and write a single value.


1 Answers

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

like image 91
Mark Baker Avatar answered Sep 29 '22 02:09

Mark Baker