Skip to content

Conversation

jtojnar
Copy link

@jtojnar jtojnar commented Jun 28, 2025

PHP 8.4 deprecates implicitly nullable parameters, i.e. typed parameter with a null default value, which are not explicitly declared as nullable.
See https://wiki.php.net/rfc/deprecate-implicitly-nullable-types

Ideally, we would just change the type hint ?DOMElement but https://wiki.php.net/rfc/nullable_types was only introduced in PHP 7.1, while we still support PHP 5.6.

This patch is a somewhat hacky alternative to #264 that fixes those warnings without breaking backwards compatibility or removing PHP < 7.1 support. We remove the offending formal arguments in favour of obtaining them with func_get_arg() and checking their type ourselves. The PHPDoc param annotations were updated to match the actual types of the now virtual arguments.

The downside is that it removes PHP 7.4’s parameter contravariance checks (https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters) so future re-introduction of the formal arguments would be a BC break.

PHP 8.4 deprecates implicitly nullable parameters, i.e. typed parameter with a `null` default value, which are not explicitly declared as nullable.
See <https://wiki.php.net/rfc/deprecate-implicitly-nullable-types>

Ideally, we would just change the type hint `?DOMElement` but <https://wiki.php.net/rfc/nullable_types> was only introduced in PHP 7.1, while we still support PHP 5.6.

This patch is a somewhat hacky alternative to <microformats#264> that fixes those warnings without breaking backwards compatibility or removing PHP < 7.1 support.
We remove the offending formal arguments in favour of obtaining them with `func_get_arg()` and checking their type ourselves.
The PHPDoc param annotations were updated to match the actual types of the now virtual arguments.

The downside is that it removes PHP 7.4’s parameter contravariance checks (https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters) so future re-introduction of the formal arguments would be a BC break.
@jtojnar jtojnar force-pushed the wip/jtojnar/php84-bc branch from 592888d to f818176 Compare June 28, 2025 11:58
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.

1 participant