The tedious task of updating to PHP v8.1
Last month, we embarked upon the task of updating our bespoke framework to support PHP 8.1.
When a new version of PHP reaches general release, it's always exciting to take a look at new features and syntax improvements.
Unfortunately, though, this time around meant a very tedious task of elaborating on a lot of shorthand coding throughout our entire framework.
At the framework's inception many years ago, we made the unfortunate mistake of coding on a server where notices were disabled. This resulted in us being unaware of PHP's preference for stricter, albeit long-winded, syntax.
The issue that came about actually relates to the following notices that have been reclassified as warnings in PHP 8.0:
-
Undefined variable: warning instead of notice
-
Undefined array index: warning instead of notice
-
Division by zero:
DivisionByZeroErrorexception instead of warning -
Attempt to increment/decrement property '%s' of non-object:
Errorexception instead of warning -
Attempt to modify property '%s' of non-object:
Errorexception instead of warning -
Attempt to assign property '%s' of non-object:
Errorexception instead of warning -
Creating default object from empty value:
Errorexception instead of warning -
Trying to get property '%s' of non-object: warning instead of notice
-
Undefined property: %s::$%s: warning instead of notice
-
Cannot add element to the array as the next element is already occupied:
Errorexception instead of warning -
Cannot unset offset in a non-array variable:
Errorexception instead of warning -
Cannot use a scalar value as an array:
Errorexception instead of warning -
Only arrays and
Traversablescan be unpacked:TypeErrorexception instead of warning -
Invalid argument supplied for foreach():
TypeErrorexception instead of warning -
Illegal offset type:
TypeErrorexception instead of warning -
Illegal offset type in isset or empty:
TypeErrorexception instead of warning -
Illegal offset type in unset:
TypeErrorexception instead of warning -
Array to string conversion: warning instead of notice
-
Resource ID#%d used as offset, casting to integer (%d): warning instead of notice
-
String offset cast occurred: warning instead of notice
-
Uninitialized string offset: %d: warning instead of notice
-
Cannot assign an empty string to a string offset:
Errorexception instead of warning -
Supplied resource is not a valid stream resource:
TypeErrorexception instead of warning
Fortunately, we have completed the core changes and are now testing the alpha release on our own internal systems! We are, subsequently, now taking advantage of the performance benefits of PHPv8.1 🙂