Guy in the blue house
Guy in the blue house

Reputation: 73

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

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?

Upvotes: 4

Views: 2649

Answers (2)

Pradeep
Pradeep

Reputation: 1254

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.

Upvotes: 13

Uku Loskit
Uku Loskit

Reputation: 42040

grep -r 'define("TEXT_PRODUCT"' *

Upvotes: 3

Related Questions