PHP 5.2 linting with MAMP

Syntax checking PHP files for 5.2 compatibility. The really easy way.

MAMP

These days I rarely use MAMP with alternatives like a local set up, Docker, Vagrant and its WordPress specific variations.
Still I consider MAMP an asset and a “just works” solution that I come to appreciate in dire times.
The local stack comes in a PRO version that’s worth its cost to me but the free version of it still packs PHP in its 5.2.17 version that’s easy and ready to use.

WordPress minimum requirements

WordPress still lists that version of PHP as its minimum required one and I want to think some plugins I’ve written “should” work on PHP 5.2.
The most recent case with Restricted Content framework plugin is that I wanted a quick way to lint my code against the older version of PHP without too much hassle.

CLI scripts

Since the older PHP version is located in the MAMP application accessing it on a Mac, is easy and convenient.
The script I came up with is a modification of this one and here is the code

#!/bin/bash

for file in `find .`
do
    EXTENSION="${file##*.}"

    if [ "$EXTENSION" == "php" ] || [ "$EXTENSION" == "phtml" ]
    then
        RESULTS=`/Applications/MAMP/bin/php/php5.2.17/bin/php -l $file`

        if [ "$RESULTS" != "No syntax errors detected in $file" ]
        then
            echo $RESULTS
        fi
    fi
done

copy and paste in a file like

cd /usr/local/bin
touch lint52
pbpaste > lint52
chmod +x lint52

Navigate then to any folder that should be lint-ed and run the command

cd /Users/Me/MySites/MyWp/wp-content/plugins/my-plugin/src
lint52

and see it pointing errors.

I appreciate your input