PHP 7.0 (and 5.6) on Ubuntu

PHP 7 is released but for those of us who don’t usually compile our own PHP, it can be a long wait for our preferred distro to release the packages we want. For Ubuntu, I’m using a PPA which allows both PHP 5.6 and PHP 7.0 to be installed, including things like extensions, at the same time. It was very easy to set up (I’m running Ubuntu 15.10 but this process should also work on older versions back to at least 14.04 which is the previous LTS) so here’s a quick walkthrough of what I did. Continue reading

Generating a File List for Phan

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. The simplest usage instructions are:

phan -f filelist.txt

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. My command looks like this:

grep -R -l "<?php" * > filelist.txt

This simply greps recursively (the -R switch) in all files looking for <?php and when it finds it, outputs only the filename (the -l switch does that bit). Then I just put all the output into my filelist.txt file.

Phan is in its early stages but it’s ready for you to run on your own projects. Look out that you may need to put your bootstrap or other include files first in the filelist.txt file if phan isn’t finding things in the right order – luckily with it all in one file, it’s relatively easy to move things around if you need to.

PHP: Calling Methods on Non-Objects

PHP has subtly changed the wording of this error between various versions of the language, which can trip up your log aggregators when you upgrade so I thought I’d give a quick rundown of the changes around the “call to member function on non-object” error in PHP, up to and including PHP 7 which has an entirely new error handling approach. Continue reading

New in PHP 7: null coalesce operator

Not the catchiest name for an operator, but PHP 7 brings in the rather handy null coalesce so I thought I’d share an example.

In PHP 5, we already have a ternary operator, which tests a value, and then returns the second element if that returns true and the third if it doesn’t:

echo $count ? $count : 10; // outputs 10

Continue reading

SOAPFault When Switching PHP Versions

I’m working on an update to my PHP Web Services book and with PHP 7 likely to release before the book even makes it into print, I’m testing all my example code across PHP 5.6 and PHP 7 … which today gave me a weird problem with a very, very simple SOAP example. Continue reading

PHP 7 Benchmarks

If you know anything at all about PHP7, you probably know it’s fast. But did you know how fast? The alpha is out and looks very robust, so I decided I would create a new set of benchmarks to include it. Graphs first, disclaimers later :)

This graph shows the time it takes for each version of PHP to perform the same task, on average, with oldest PHP on the left and moving forward in time.

php-70-alpha-benchmarks

Continue reading

PHP7: Easiest Upgrade Yet

With PHP7 looking increasingly stable (relatively speaking, it’s still pre-alpha so it’s VERY early days and anything could happen!), and work going well on the GoPHP7-ext project to get extensions converted, I have been thinking about the migration guides we’ll need to help people upgrade their existing applications. To this end, I took the simplest project I currently have (http://api.joind.in) and gave it a whirl on PHP7, using Rasmus’ PHP7 dev box. The result:


Continue reading