Porting from PHP4 Era Code to PHP7

It was, surprisingly, not that bad. (So far. It’s not done yet.) Here’s a rundown of how it was done. Ask questions in the comments, because this will be brief.

The Setup

The code was written back in the PHP4 days, but I had the server upgraded to use PHP 5.6, which has a lot of features we need, and will run PHP 7 compatible code. There’s just not enough overlap between PHP4 and PHP7.

Then, I set up Apache to run PHP5.6, and proxy selected URLs to PHP7 running in PHP-FPM.

This way, I could subject one section of the website to PHP7, and work on it.

I was hoping to do the work in a development environment, but setting up a dev environment was HARD. It’s also really hard to test thoroughly in the regular way.

So, I did it in-place on the live server. I’d just get the most popular code paths working. All other errors go to the logs, and I’ll scan those later to find bugs to fix.

The Techniques

  • Subject directories to PHP7
  • Use a new namespace for the ported code.
  • Rewrite the DB abstraction layer.
  • Make some useful VIM macros for frequent code edits.

Leave a Reply