Common causes
- Parameters were reordered or a new required parameter was added at the end
- Old code written for PHP 5 or 7, where this was silently allowed
- Copying signatures from older WordPress or framework code
- Using = null for a nullable type instead of the ?Type syntax
How to fix it
- Open the function in the message. Go to the file and line shown. Note which optional parameter appears before which required one.
- Move required parameters first. Reorder the signature so all required parameters come before optional ones, for example function get($type, $limit = 10). Update every call to match the new order.
- Or remove the useless default. If you cannot change call sites safely, delete the default value, for example function get($limit, $type). This does not change behaviour because the default was never used.
- Use ?Type for nullable parameters. Write ?Foo $foo instead of Foo $foo = null when the parameter is required but may be null. Note that PHP 8.4 also deprecates implicit nullable types (Foo $foo = null), so ?Foo is the safe form.
- Update third-party code. If the file is inside a plugin, theme or vendor folder, update that package rather than editing it, so your fix is not lost on the next update.
Before and after reordering parameters
// Deprecated
function fetchPosts($limit = 10, $type) { }
// Fixed: required first
function fetchPosts($type, $limit = 10) { }
// Required but nullable
function send(?Logger $logger, string $msg) { } How to stop it happening again
- Always put required parameters before optional ones
- Use named arguments in PHP 8 instead of long optional lists
- Test with deprecation notices visible before upgrading PHP
- Run a PHP compatibility scan on legacy code