Hailwood Posted February 18, 2010 Share Posted February 18, 2010 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 More sharing options...
sader Posted February 18, 2010 Share Posted February 18, 2010 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 https://forums.phpfreaks.com/topic/192478-where-is-variable-defined/#findComment-1014197 Share on other sites More sharing options...
Hailwood Posted February 18, 2010 Author Share Posted February 18, 2010 Yeah cheers, i already know those, im talking about a function i could call anywhere on a variable and it will return it... Link to comment https://forums.phpfreaks.com/topic/192478-where-is-variable-defined/#findComment-1014218 Share on other sites More sharing options...
trq Posted February 18, 2010 Share Posted February 18, 2010 Short answer is no. You could likely write a program to find it, or get a decent editor. Link to comment https://forums.phpfreaks.com/topic/192478-where-is-variable-defined/#findComment-1014242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.