Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /data/e/7/e76990b9-3372-4d88-8089-fce36e16744a/webperfection.net/sub/rady-nosu/wp-content/plugins/seo-ultimate/modules/class.su-module.php on line 1195
phan php7 static analyzer

December 14, 2015 | In: Programovanie

running phan static analyzer to check php5 to php7 issues

how to run phan on debian

First, go here, here and here to get an idea about how to get phan working.

For Debian8 though, I had to do a few more tricks to get it running.

If you still haven’t try php7 (shame on you!) check this guide: how to install php7 on debian8 and redhat6.

To compile phan, you will need a phpize. For some reason it couldn’t resolve the dependencies automatically so here is what you will need:

aptitude install autoconf automake autotools-dev libltdl-dev libssl-dev libssl-doc libtool shtool

than php readline and sqlite3:

aptitude install php7.0-readline php7.0-sqlite3

and finally you should be able to install:

aptitude install php7.0-dev

You can now go back to phan and you should be able to compile it (finally):

$ git clone git@github.com:nikic/php-ast.git
$ cd php-ast
$ phpize7.0
$ ./configure --enable-ast 
$ make install

This will build your ast.so, which is located (on debian8):

ls /usr/lib/php/20151012/

Now you need to configure php-cli and load your new module. Check where the all the interesting ini/conf files are:

php --ini

On Debian you probably want to check:

cd /etc/php/7.0/cli/conf.d/
echo 'extension=ast.so' > 20-ast.ini

If everything went fine (like it ever does…), you are good to go with phan install:

$ composer global require etsy/phan:dev-master

That should do the trick and you can run phan from your command line:

cd my_php_project;
phan -i -b -p `find ./ -type f -path '*.php'` > static_anal.report

And if you are lucky enough, and wont end up with segmentation fault as I did (try to run it on sub folder), you will see a lot of interesting things:

.../NeolaneController.php:72 TypeError assigning object to property but \default_neolanecontroller::proxy is array
.../ExactTarget/Et.php:258 ParamError call with 4 arg(s) to \soapvar::__construct() which only takes 0 arg(s)
.../CreateTextVersionDynamic.php:318 TypeError string passed to foreach instead of array
.../Editors/HTMLEditor.php:99 VarError Variable $element is not defined
.../Editors/DynamicEmails.php:105 TypeError arg#2(search) is \Service\Editors\stdclass but \array_key_exists() takes array
.../Editors/DynamicEmails.php:703 TypeError arg#2(subject) is string but \preg_replace_callback_array() takes array
.../Editors/DynamicEmails.php:721 TypeError arg#1(masterId) is int but \Service\Editors\dynamicemails::setmasterid() takes \Service\Editors\type defined at .../Editors/DynamicEmails.php:767
.../Editors/DynamicEmails.php:912 ParamError call with 3 arg(s) to \Service\Editors\dynamicemails::createviewrow() which only takes 2 arg(s) defined at .../Editors/DynamicEmails.php:926
.../Accounts.php:261 TypeError return \Service\type but getUsers() is declared to return array

If you want to experiment with other libraries, checkout the post from php7 analysis tools.

Share This:

Comments are closed.