Ken Guest’s online diary

May 14, 2015

Phing: Lint PHP code with a different interpreter.

Filed under: phing,php — kenguest @ 08:15

There’s an old server somewhere that creaks along and runs php 5.3 for legacy purposes. Recently one of the services running on that stack started throwing “internal server errors”, due to my use of array short form notation (“[…]”) which came along in php5.4, rather than using “array(…)”.

This wasn’t caught before the deploy because php 5.4 and 5.5 are used everywhere else.

So, what to do to ensure this doesn’t happen again? (Asides from investing effort in upgrading the 5.3 “locked” services to a much more recent version of PHP.)

We use phing for managing our “build process”, so using Christian’s phpfarm tool for installing multiple versions of php, I installed  a cli instance of php5.3 and changed the phplint task in my phing build.xml file to look something like this:

<phplint haltonfailure="true" interpreter="${lintInterpreter}" deprecatedAsError="true">
  <fileset refid="application"/>
  <fileset refid="vendors"/>
 </phplint>

This also meant adding a lintInterpreter line to my buildproperties.ini file as I prefer to have any configurable properties refactored out from my build.xml to a seperate file.

These are what the relevant parts of those files look like:

$ cat buildproperties.ini 
builddir=build
lintInterpreter=/usr/local/php-5.3.28/sapi/cli/php
$ head -n5 build.xml 
<?xml version="1.0"?>
<!-- phing build xml -->
<project name="ProjectName" default="main">
 <property file="buildproperties.ini"/>

And that should take care of that.
Advertisements

1 Comment »

  1. […] is a build system that I’ve written about before which is open source, and developed in […]

    Pingback by Getting phing custom tasks up to PR standard. What I did. | Ken Guest’s online diary — November 5, 2015 @ 13:44


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.