New in PHP 8.0 Match control structure Attributes Nullsafe object 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"
Getting Ready for a New PHP Version Compatible Dev Dependencies • Composer • Test Tools • Static Analysis Tools • Xdebug • PHP Scoper Compatible Runtime Dependencies Learn, Scan, Test & Fix Start Using New Features*
Getting Ready for a New PHP Version Compatible Dev Dependencies • Composer • Test Tools • Static Analysis Tools • Xdebug • PHP Scoper Compatible Runtime Dependencies Learn, Scan, Test & Fix Start Using New Features*
Getting Ready for a New PHP Version Compatible Dev Dependencies • Composer • Test Tools • Static Analysis Tools • Xdebug • PHP Scoper Compatible Runtime Dependencies Learn, Scan, Test & Fix Start Using New Features*
Scan vs Test Results depend on Tool Capabilities & Readiness Unit Tests Integration Tests E2E Tests Acceptance Tests …. Results depend on Test Suite Completeness PHPCompatibility PHPStan Psalm Exakat
Getting Ready for a New PHP Version Compatible Dev Dependencies • Composer • Test Tools • Static Analysis Tools • Xdebug • PHP Scoper Compatible Runtime Dependencies Learn, Scan, Test & Fix Start Using New Features*
Getting Ready for a New PHP Version Compatible Dev Dependencies • Composer • Test Tools • Static Analysis Tools • Xdebug • PHP Scoper Compatible Runtime Dependencies Learn, Scan, Test & Fix Start Using New Features*
Reserved Keywords ▪ New Reserved Keyword(s): - match - enum (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;
Error Handling ▪ @ no longer silences fatal errors ▪ 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()
New Errors spl_autoload_register will throw TypeError XML-RPC moved to PECL Incompatible overloaded method signatures (LSP) Abstract trait method signature validation Invalid signatures for magic methods final private Reflection export() parent:: without parent class
New Deprecations in PHP 8 Passing null to non- nullable PHP native functions (8.1) Various functions and methods Optional parameters before required Sorting callbacks returning boolean
Other changes in Function Parameter or Return Types substr() et 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
An Example declare(strict_types = 1); vprintf( 'The %s', 'dog' ); 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
Getting Ready for a New PHP Version Compatible Dev Dependencies • Composer • Test Tools • Static Analysis Tools • Xdebug • PHP Scoper Compatible Runtime Dependencies Learn, Scan, Test & Fix Start Using New Features*
For public/OS code: ❑ Isolate the problem ❑ Write tests before attempting a fix Make sure the tests include other unhappy paths! ❑ Create the fix ❑ [Optional, but recommended] While you're add it, add some more tests Example: https://core.trac.wordpress.org/ticket/52534 BEWARE OF BC BREAKS
Named Parameters Any parameter name change is now a breaking 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);
Getting Ready for a New PHP Version Compatible Dev Dependencies • Composer • Test Tools • Static Analysis Tools • Xdebug • PHP Scoper Compatible Runtime Dependencies Learn, Scan, Test & Fix Start Using New Features*
New in PHP 8.0 Match control structure Attributes Nullsafe object 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
“ For well-typed codebases or codebases which have stayed up-to- 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"
Biggest Issues * Insufficient Tests AJAX calls hiding problems Filters, filters and more filters * Both for WordPress Core as well as for plugins and themes https://core.trac.wordpress.org/ticket/51525
"beta-compatible" Fix all KNOWN issues based on tests Fix all issues based on scans New PHP 8 issues being reported every week Undiscovered issues ? Parameter name review Plugins & themes not being compatible Plugins & themes doing it wrong™