Find where a variable is defined in PHP (And/or SMARTY)?

后端 未结 6 850
忘掉有多难
忘掉有多难 2020-12-17 22:05

I\'m currently working on a very large project, and am under a lot of pressure to finish it soon, and I\'m having a serious problem. The programmer who wrote this last defin

6条回答
  •  醉话见心
    2020-12-17 22:18

    There is an interesting further option, ugly like hell but helpful if you are really lost.

    If you would like to know where THE_NAME was defined, write lines like these on a place you are sure is run first:

    error_reporting(E_ALL);
    define('THE_NAME', 'Chuck Norris');
    

    If later PHP will run the definition you are looking for, it will write a notice like this:

    Notice: Constant THE_NAME already defined 
    in /home/there/can-rip-a-page-out-of-facebook.com/SomeConfiguration.php on line 89 
    

    Then you know that the definition you are looking for is in the file SomeConfiguration.php on line 89.

    To have this working, you must consider

    • if there are HTTP forwards in the framework on the way to the code you set in
    • if there are further commands setting the PHP error reporting mode

    So sometimes it helps to add some exit('here') in order not to blur the output. Maybe you have to narrow down a bit or you have to set error_reporting earlier, but you'll find it.

提交回复
热议问题