Gravid Banner

“When you’re up to your neck in alligators, it’s hard to remember that your initial objective was to drain the swamp”

It seems quite appropriate that in wanting to start a tech blog about the difficulties in keeping up to date, I should start by having to update a whole bunch of dependencies. My web-host has WordPress as a one click add-in. So very simple. Or rather, so very not.

The issue was neither the hosting nor the installer. It was the legacy sites in my hosting account. Two particular projects that I built back in 2004 and have migrated across several hosting platforms with minimal changes. Both of them currently running in PHP 7.3 – one version behind the minimum needed for the latest version of WordPress. Even moving the PHP version forward one step broke both sites.

Delving back into code written such a long while back is always going to be tricky. One of the sites was my first ever PHP and it was pretty messy. It took a bit of effort going through the error logs to narrow it down, but eventually the problem came down to three things:

  1. Using GZIP in a template class to compress the HTML
  2. Using the each() function to transform an array into key, value pairs
  3. Using PHP short open tags

It took a while to find them all, buy they were all an easy fix. For the GZIP I opted to switch it off. Easier to disable it than figure out why it wasn’t working. It is an old site and it doesn’t get much traffic – so I switched it out.

For the second I was surprised to see that each() had been deprecated. Probably not news to anyone as it was back in 2017 – but it illustrates the issues with legacy code

Fortunately is easy enough to replace

while(list($key, $value) = each($array))
PHP

with

foreach($array as $key => $value)
PHP

and a standalone

list($key, $value) = each($array);
PHP

with

$key = key($array);
$value = $array($key);
PHP

The final piece of the puzzle was simply to set short_open_tag to on in php.ini – in CPanel this can be accomplished in the options tab of the PHP selector.

The fact that I am now writing my first WordPress blog is proof that I got it all working.

Sadly I haven’t been able to update past PHP 8.1 as I also have a whole MySQL class based on mysqli which was end of life in 8.2 – but I have left that as a job for another day.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *