When upgrading to PHP 7, you might run into really hard-to-debug error messages which might be a result of the uniform variable syntax RFC.
This script (forked from Nikita Popov's gist) will scan a PHP 5 codebase and call out the file and line number of an indirect expression with an offset. The evaluation of these expressions has changed in PHP 7.
To run this script against a PHP 5 codebase, make sure you have PHP and Composer installed. Then create a directory somewhere and install nikic/php-parser
with Composer.
$ mkdir ~/uvs-bug-finder && cd "$_"
$ composer require nikic/php-parser
Then either copy/paste the script in this gist into a PHP file called uvs-bug-finder.php
, or just download the raw file directly with PHP:
$ php -r "copy('https://gist.githubusercontent.com/SammyK/5d942381e396bba84a49aa3c722cd2c7/raw/d615884bf7b667a94885b113a253026ab6bf0ed3/uvs-bug-finder.php', 'uvs-bug-finder.php');"
If the PHP 5 project you want to scan lives at /path/to/project
, you can send the directory path to the script as a CLI argument.
$ php uvs-bug-finder.php /path/to/project
/path/to/project/test.php @ 15:
FooBar::$methods[0]();
/path/to/project/test.php @ 18:
var_dump(DateTime::$bar['method_name']());
The errors can typically be fixed by wrapping the offset-part of the expression with curly brackets. So using the example above that was found in test.php
on line 18...
/path/to/project/test.php @ 18:
var_dump(DateTime::$bar['method_name']());
...we simply open up the PHP file, go to line 18 and add curly brackets around the offset part like this...
var_dump(DateTime::{$bar['method_name']}());
And that should fix it! Good luck! :D