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
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";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.