Skip to content

PHP 8.1 | WP_CLI\Iterators\CSV: fix "missing return type" deprecation warnings #5983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Sep 16, 2024

As of PHP 8.1, PHP started throwing deprecation warnings along the lines of:

Deprecated:  Return type of [CLASS]::[METHOD]() should either be compatible with [PHP NATIVE INTERFACE]::[METHOD](): [TYPE], or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

These type of deprecation notices relate to the Return types for internal methods RFC in PHP 8.1.

Basically, as of PHP 8.1, these methods in classes which implement PHP native interfaces are expected to have a return type declared. The return type can be the same as used in PHP itself or a more specific type. This complies with the Liskov principle of covariance, which allows the return type of a child overloaded method to be more specific than that of the parent.

As this package still has a minimum PHP requirement of PHP 5.6, the return type (PHP 7.0 feature) can not be added, so I've added the attribute instead.

While attributes are a PHP 8.0 feature only, due to the syntax choice for #[], they will ignored in PHP < 8 and can be safely added.

Note: these deprecations were visible in the test summary, but the tests - as they currently are - are not set up correctly to fail builds on deprecation notices, which is probably why this went unnoticed.

@jrfnl jrfnl requested a review from a team as a code owner September 16, 2024 22:10
@jrfnl jrfnl force-pushed the feature/php-81-fix-return-type-deprecation-notices branch from d2db809 to 6ed0b4f Compare September 17, 2024 15:55
@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 17, 2024

Rebased without changes after the merge of #5982. This should allow to get a passing build.

@swissspidy swissspidy added this to the 2.12.0 milestone Sep 17, 2024
@swissspidy swissspidy merged commit b852d18 into wp-cli:main Sep 17, 2024
42 checks passed
@jrfnl jrfnl deleted the feature/php-81-fix-return-type-deprecation-notices branch September 17, 2024 16:30
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