Pragmatism in the real world

Installing Phan on OS X

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.

I started by trying to install Phan into my global composer install so that it’s available on my path. As it’s not released on Packagist, I edited ~/.composer/composer.json and added:

    "repositories": [
            "type": "vcs",
            "url": ""

to the top, so the I could then install via the standard composer method:

$ composer global require etsy/phan:dev-master

This immediately failed as I don’t have the Nikita’s ast extension installed:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for etsy/phan dev-master -> satisfiable by etsy/phan[dev-master].
    - etsy/phan dev-master requires ext-ast * -> the requested PHP extension ast is missing from your system.

To install this extension:

$ git clone
$ cd php-ast
$ phpize
$ ./configure --enable-ast
$ make install

Now edit you php.ini file (/usr/local/etc/php/7.0/php.ini for Homebrew installations) and add at the bottom.

Having installed the ast PHP 7 extension, Phan will now install:

$ composer global require etsy/phan:dev-master
Changed current directory to /Users/rob/.composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)         
  - Installing etsy/phan (dev-master 66dd303)
    Cloning 66dd303fc17aafe968fa5ff393b920ba5c222b6f

Writing lock file
Generating autoload files
Changelogs summary:

 - etsy/phan installed in version dev-master

Now, Phan works from my command line!

$ phan -h
Usage: /Users/rob/.composer/vendor/bin/phan [options] [files...]
  -f <filename>   A file containing a list of PHP files to be analyzed
  -q              Quick mode - doesn't recurse into all function calls
  -b              Check for potential PHP 5 -> PHP 7 BC issues
  -i              Ignore undeclared functions and classes
  -c              Comma-separated list of classes that require parent::__construct() to be called
  -m <mode>       Output mode: verbose, short, json, csv
  -o <filename>   Output filename
  -p              Show progress bar
  -t              Emit trace IDs on messages (for grouping error types)
  -s <filename>   Save state to the given file and read from it to speed up
                  future executions
  -r              Force a re-analysis of any files passed in even if they haven't
                  changed since the last analysis
  -h              This help

2 thoughts on “Installing Phan on OS X

  1. Nice article!
    Also it is possible to install ast with homebrew (brew install php70-ast).

Comments are closed.