Skip to content

php 8.4: fix implicit nullable parameter declarations#216

Merged
falkenhawk merged 4 commits intophp84-compatfrom
php84-nullable
Apr 3, 2026
Merged

php 8.4: fix implicit nullable parameter declarations#216
falkenhawk merged 4 commits intophp84-compatfrom
php84-nullable

Conversation

@falkenhawk
Copy link
Copy Markdown
Member

@falkenhawk falkenhawk commented Apr 2, 2026

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 ?Type syntax 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 (like ReturnTypeWillChange did 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.x branch 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 on 1.15.x releases.

1.15.x versions 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 with 1.15.x, then upgrade PHP to a commonly supported version (7.1-8.3), then switch to 1.16.x.

What changed

  1. Fix implicit nullable parameter declarations - applied ?Type syntax to all 277 implicitly nullable parameters across 156 files, using php-cs-fixer's nullable_type_declaration_for_default_null_value rule
  2. Bump minimum PHP version to 7.1 - updated all 88 composer.json files
  3. Drop symfony/polyfill-php70 - no longer needed with PHP 7.1 minimum

marcing and others added 4 commits April 3, 2026 09:31
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
@falkenhawk falkenhawk changed the base branch from php84-compat to php84-e-strict April 3, 2026 11:58
@falkenhawk falkenhawk marked this pull request as ready for review April 3, 2026 11:58
Base automatically changed from php84-e-strict to php84-compat April 3, 2026 11:59
@falkenhawk falkenhawk merged commit 7705756 into php84-compat Apr 3, 2026
10 checks passed
@falkenhawk falkenhawk deleted the php84-nullable branch April 3, 2026 12:00
@falkenhawk falkenhawk mentioned this pull request Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants