php 8.4: fix implicit nullable parameter declarations#216
Merged
falkenhawk merged 4 commits intophp84-compatfrom Apr 3, 2026
Merged
php 8.4: fix implicit nullable parameter declarations#216falkenhawk merged 4 commits intophp84-compatfrom
falkenhawk merged 4 commits intophp84-compatfrom
Conversation
4d1f79c to
4bb4e8a
Compare
add explicit ?Type syntax to all 277 implicitly nullable parameters across 156 files, using PHP-CS-Fixer's nullable_type_declaration_for_default_null_value rule. PHP 8.4 deprecated implicit nullable (`Type $param = null`), requiring explicit `?Type $param = null` instead.
the ?Type nullable syntax required for PHP 8.4 compatibility is only available from PHP 7.1 onwards https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated
no longer needed with php 7.1 minimum
4bb4e8a to
4c8a26e
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Alternative approach to #207
The problem
PHP 8.4 deprecated implicit nullable parameter declarations. This means
function foo(SomeClass $param = null)now emits a deprecation notice, and PHP 9.0 will turn it into a fatal error. The fix is to use explicit nullable syntax:function foo(?SomeClass $param = null).The catch is that
?Typesyntax was only introduced in PHP 7.1 - there is no syntax that works on both PHP 5.3 and PHP 8.4. This is not a situation where a polyfill or#[\Attribute]trick can help (likeReturnTypeWillChangedid for PHP 8.1). Every major PHP project that hit this wall - WordPress, Laravel, Drupal, CodeIgniter - ended up bumping their minimum PHP version.Why we're changing direction
Up until now, this fork maintained compatibility with the full range of PHP versions down to 5.3. That was always a core principle - keep the barrier to entry as low as possible for legacy projects.
PR #207 tried to preserve that by removing type hints and adding runtime checks via
Zf1s\Compat\Types::isNullable(). It worked, but as @dmnc pointed out, it introduced a "surprising pattern" and raised the question whether bumping to >=7.1 would be preferable. A similar discussion happened on the phpunit side (zf1s/phpunit#22), where the compat class approach was eventually superseded by inline checks in #25.In the end, there's no clean way to support both PHP 5.3 and 8.4 for this particular deprecation. Removing type hints to work around a language change goes against the goal of keeping the codebase close to the original - it replaces one problem with another. Bumping to 7.1 was chosen as the most reasonable way out of this situation.
What this means for users on older PHP
The
1.15.xbranch has been created from the last release (1.15.6) that supports PHP 5.3-8.3. It may receive backported fixes if time allows. Projects on PHP 5.3-7.0 should stay on1.15.xreleases.1.15.xversions may also be useful as a stepping stone when migrating a project from an older PHP version (<7.1): first make sure everything works on your current PHP version with1.15.x, then upgrade PHP to a commonly supported version (7.1-8.3), then switch to1.16.x.What changed
?Typesyntax to all 277 implicitly nullable parameters across 156 files, using php-cs-fixer'snullable_type_declaration_for_default_null_valuerulecomposer.jsonfilessymfony/polyfill-php70- no longer needed with PHP 7.1 minimum