Jump to content

Where is variable defined?


Hailwood

Recommended Posts

Hi there,

 

 

Is there any way in php to ask it to output the filename and line that a particular variable is defined?

 

 

eg

 

 

echo whereIs($date);

 

 

would output test.php :391

 

 

or something similar,

 

 

this is because i have a whole pile of includes (mostly from a framework) and i need to find out where a particular var is coming from!

 

 

Link to comment
https://forums.phpfreaks.com/topic/192478-where-is-variable-defined/
Share on other sites

there are some "magic constants":

__LINE__

__FILE__

__FUNCTION__

__CLASS__

__METHOD__

 

it's not exactly what u are asking but i guess to do what u want could be done like this(in my opinion it looks a bit dump :))

 

$var_defined_at = (__LINE__+1).":".__FILE__ ;

$var = "value";

 

echo "\$var defined at:$var_defined_at";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.