Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Master Zend Framework:
Preparing Legacy Applications for PHP 7 with Phan
Sep 08, 2016 @ 17:07:42

The Master Zend Framework site has posted a new tutorial for those making the move in their legacy applications up to the world of PHP 7. In it Matthew Setter shows how to use phan, a static analysis tool, to locate issues that could cause breakage in the upgrade.

Unless you’ve been living under a rock these last 12 - 18 months, you will have heard about PHP 7; the latest version of PHP. Not only is it fast, by some reports it’s up to twice as fast as PHP 5.6, and far less memory hungry.

[...] Unfortunately, your application’s source code may not be 100% compatible with version 7. Upgrading may well leave you with a broken application and a set of unhappy customers. So before you go breaking your site in the interests of speed and being one of the cool kids, find out if your code’s compatible. How? By using a static code analyser, one which gives you all the changes you need to make on your code, so that you can upgrade with confidence.

He then shows how to install the Phan tool via Composer and execute it against your codebase. The result of his commands are a file that contains the issues found during the scan. If there are some "false positives" you'd like to ignore he also shows you how to create a config.php file with these and other values set to make it all more reusable.

tagged: php7 upgrade phan detect static analysis code tutorial

Link: http://www.masterzendframework.com/preparing-for-php7-with-phan/

Rob Allen:
Running Phan against Slim 3
Dec 10, 2015 @ 15:51:20

Rob Allen has a quick post sharing the results of a test run of the Phan static analysis tool on the current state of the Slim 3 framework codebase (with v3.0 just being released).

Having installed Phan, I decided to use it against the upcoming Slim 3 codebase.

Phan needs a list of files to scan, and the place I started was with Lorna's article on Generating a file list for Phan.

He walks through the steps for creating this list of files (removing developer dependencies) and the results from the Phan execution. While a good amount of the errors related more to dependencies and missing class/interface definitions, there were some typing errors found based on the difference between the docblock and how the code handled the variable.

tagged: phan static analysis tool slim3 framework results

Link: https://akrabat.com/running-phan-against-slim-3

Rob Allen:
Installing Phan on OS X
Dec 03, 2015 @ 15:27:37

Rob Allen has posted a quick tip to his site showing how to get Phan installed on an OS X system. Phan is a static analysis tool written for PHP 7 and makes use of the new functionality that exposes the AST for the underlying language.

I use Homebrew for my local PHP installation on OS X and am currently running PHP 7.0.0 RC8.

Phan is a static analyser for PHP 7 which was written by Rasmus and then rewritten by Andrew Morrison. As it benefits from PHP 7's abstract syntax tree it can find all kinds of subtle errors, so I wanted to install it locally to have a play with it.

He shows how to get the tool installed via Composer (with a custom repository definition) and links to the ast extension you'll need installed to let the tool work. A quick exit to your php.ini file is then all it takes to complete the installation and let you install and run the tool from the command line.

tagged: phan static analysis tool php7 install configure osx

Link: http://akrabat.com/installing-phan-on-os-x/

Lorna Mitchell:
Generating a File List for Phan
Nov 27, 2015 @ 16:38:33

Lorna Mitchell has shared a tip she's found helpful when using the phan static analysis tool for finding only PHP files via a simple grep.

Phan is the PHP Analyzer for PHP 7 code. I've been using it, partly out of curiosity, and partly to look at what the implications of upgrading my various projects will be. [...] I generated my filelist.txt files with a little help from grep - by looking for all files with opening PHP tags in, and putting that list of filenames into a file.

The phan tool is still pretty young but it provides a good example of how to use the new php-ast handling to parse and analyze PHP code.

tagged: phan file list generate quick tip grep static analysis tool

Link: http://www.lornajane.net/posts/2015/generating-a-file-list-for-phan


Trending Topics: