Top 4 most common issues while Upgrading your Joomla website to PHP 7.2

2018 marked the "End of Life" for PHP 5.6 and 7.0. In the very near future, PHP 7.1 will come to it's "End of Life". You may have seen the big red warning on your Joomla administrator panel regarding the upgrade and may have even attempted at upgrading PHP yourself only to have your Joomla site crash (blank page).

Lately we’ve dealt with multiple sites, some of them not even running the latest Joomla, that required specific fixes to have PHP 7.2 running. Although each site is unique when customizations are present, we were able at IDL Web to narrow some of the causes for a failed PHP Upgrade.

1. Up-to-date Extensions

This sounds already like a cliché for CMS and their extensions, but yes, since PHP 5 to 7 presented substantial modifications to some syntax and code properties. Often time developers committed to maintain their extensions keep their code up to date and you will need to grab latest updates of all 3rd party extensions installed on your Joomla website. Keep in mind, not all of your extensions may be using the Joomla Update system. You may not see them on the “update” section of your administrator, and you will have to review/debug which extension can be causing the issue and check if there is any available update.

2. .htaccess File

This PHP upgrade has become a common request from customer to their hosting providers. Even as close to the "End of Life", some hosting providers didn’t have the option installed to make the switch to a newer PHP version. This resulted in customers moving to other hosting providers or companies refreshing their OS/Compilations. We’ve seen when moving sites and trying to upgrade others that handlers placed in the htaccess file intended to work for previous versions of PHP causes errors when PHP 7.2 is enabled. Since these handlers were placed for previous PHP versions. You will need to check with your hosting provider, but you can try removing any handlers (don’t forget to make a backup), or just placing a fresh Joomla htaccess version to check if it works with PHP 7.2

3. Fatal Error: 0 Using $this when not in object context

This error may have multiple causes, but we found 90% of the time is due to an old way of getting the menu object by templates or extensions.

Search in your template or your old extensions with issues for something like:

JSite::getMenu() or Joomla\CMS\Application\SiteApplication::getMenu()

This calls the getMenu in a static context, which is the incorrect way of calling that method.

The code should be

JFactory::getApplication()->getMenu()

4. Error: [] operator not supported for strings.

Another PHP error with multiple possible sources, but usually found in Joomla templates and extensions assigning values. Previously, it didn’t throw an error, which it does now on PHP 7.2 Search for any array not declared but set later to [] like:

$css = ''; and then later used like: $css[] = ' style="width:'.trim($column_widths[$i]).'px;"';

(Very common in old Gantry framework templates)

First line should be changed to

$css = array();

You will need to locate all instances of variables with issues like this and adjust the code.

You may just be getting a blank page or a 500 Internal Server error after your upgrade, don’t forget to enable all error reporting, Joomla debug system and PHP error reporting in your configuration so you can trace back the source of the error and check if any of the causes above may help. Joomla Core is 100% PHP 7.2 compatible. Rest assured the issue is not a core extension and invest your time to look on your 3rd party addons.

If you are not comfortable modifying the code or can't upgrade any of your Joomla extensions, leave the work to the professional Joomla developers with more than 100+ sites upgraded successfully to PHP 7.2. At IDL Web Inc, we will help you so you have your Joomla website running with the latest and greatest software.