operator Trailing comma in closure use Constructor property promotion Non capturing catch Union types Mixed type Static return type Throw expressions Stringable Magic method signature check Stable sorting ::class on objects Syntax tweaks Named arguments Reclassify engine warnings Saner numeric strings Saner string to number comparisons Locale independent float to string cast Stricter type check for arithmetic/ bitwise operators Consistent type errors for internal functions "bug fixes"
(low = less) ▪ Use v 10.0.0 / develop with recent PHP_CodeSniffer ▪ Run with --runtime-set testVersion 5.6- Psalm PHPStan PHPCompatibilityWP Running Scans WP
mixed - enum (PHP 8.1) - never (PHP 8.1) ▪ Reserved keywords can now be used in namespace names ▪ Trade off: white space no longer allowed in namespaced names namespace My\Global\Classes; use My\VeryLong\VeryLong\ NamespaceName\ClassName;
Default error level E_ALL (previously excluded E_NOTICE and E_DEPRECATED) ▪ display_startup_errors enabled by default ▪ $php_errormsgno longer available ▪ Custom error handlers will no longer receive $errcontext ▪ Uncaught Exceptions will go through "clean shutdown" ▪ exit() in __construct() will no longer call __destruct()
al vprintf() et al get_class_vars() filter_input() strtr() decbin() decoct() dechex() sem_get() datefmt_create() mb_decode_numericentity() mb_ereg[i]() pg_fetch_all() quote_meta() various enchant functions parse_url() * … and more
); vprintf( 'The %s', ['dog'] ); PHP < 8.0 PHP 8.0 The dog Uncaught TypeError: vprintf(): The dog Argument #2 ($values) must be of type array, string given
); vprintf( 'The %s', ['dog'] ); PHP < 8.0 PHP 8.0 The dog Uncaught TypeError: vprintf(): The dog Argument #2 ($values) must be of type array, string given
a fix Make sure the tests include other unhappy paths! ❑ Create the fix ❑ [Optional, but recommended] While you're at it, add some more tests Example: https://core.trac.wordpress.org/ticket/52534 BEWARE OF BC BREAKS
change ❑ Review all parameter names for all non-private functions Recommended: don't use reserved keywords for parameter names ❑ Ensure parameters in overloaded methods are in sync with the parameter name in the parent class ❑ Review all calls to call_user_func_array() Open WordPress Core ticket: https://core.trac.wordpress.org/ticket/51553 function foo( $bar, $options = [], $strict = false ) {} foo(bar: $value); foo($value, strict: true);
operator Trailing comma in closure use Constructor property promotion Non capturing catch Union types Mixed type Static return type Throw expressions Stringable Stable sorting ::class on objects Syntax tweaks Named arguments
date with the latest PHP versions, there isn’t a big problem. The reality, however, is that WordPress is not such a codebase. "The 2020 WordPress and PHP Compatibility Report"
issues based on scans New PHP 8 issues being reported every other week Undiscovered issues ? Parameter name review Plugins & themes not being compatible Plugins & themes doing it wrong™