Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find where a php var or constant has been set?

Tags:

php

This php script I'm working on has a million includes and I'm trying to find where the constant TEXT_PRODUCT has been defined (what filename and line number) is this possbile?

like image 960
Guy in the blue house Avatar asked Dec 05 '22 21:12

Guy in the blue house


1 Answers

if you want to check for one time where it gets defined, define TEXT_PRODUCT at start of your script as. So whenever PHP script tries to define it again in any file it will give notice level error that it is defined previously. But you have to define your own error handler to get exact line number and file

     <?php

     function customeHandler($errno, $errstr, $errfile, $errline){
         echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
         echo "At line ", $errline , "<br />";
         echo "At file ", $errfile , "<br />";;
             return true;
      }

      $old_error_handler = set_error_handler("customeHandler");

      define("TEST",3);

So whenever, we again define same variable in any file, it will display notice level error on screen and you can get file name as well as line no. using this.

like image 131
Pradeep Avatar answered Dec 10 '22 10:12

Pradeep