Skip to content

Add ReturnTypeWillChange to PDO implementations #4662

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

Merged
merged 1 commit into from
Jun 26, 2021

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Jun 5, 2021

Q A
Type bug
BC Break no
Fixed issues N/A

Summary

PHP 8.1 will introduce a process to add return types to internal methods, see https://wiki.php.net/rfc/internal_method_return_types

This library extends various PDO classes and overrides public methods that are affected by this change. PHP 8.1 triggers deprecation warnings unless we declare that a future version of this library will add these return types as well. We can do so by adding the ReturnTypeWillChange attribute to those methods.

This PR suggests to do just that because adding the actual return types would break code that extends our classes. IIRC, the affected classes have been removed in 3.0 anyway, so let's just get rid of the warnings. 🙂

@derrabus
Copy link
Member Author

derrabus commented Jun 5, 2021

I would consider all PHP CodeSniffer failures to be false positives. Please advice how I should tackle them.

Edit:

@morozov
Copy link
Member

morozov commented Jun 5, 2021

I hope by the time when PHP 8.1 is released we'll drop the support for DBAL 2.x. It has already sucked a lot of blood from us.

I don't believe this patch is relevant.

@derrabus derrabus force-pushed the bugfix/return-type-will-change branch from c386128 to 6d238fb Compare June 5, 2021 18:32
@derrabus
Copy link
Member Author

derrabus commented Jun 5, 2021

I hope by the time when PHP 8.1 is released we'll drop the support for DBAL 2.x.

I would hope so, but I wouldn't bet on it just yet. 🙈

It has already sucked a lot of blood from us.

True!

I don't believe this patch is relevant.

I've opened the PR because the deprecations bubbled up in Symfony's CI. But there's no urgency to fix them yet. If ORM is compatible with DBAL 3 before PHP 8.1.0 is out, we're fine I guess. That's the only blocker at the moment, isn't it?

Then again, once the issues with the CS ruleset have been sorted out, this change isn't particularly heavy.

@morozov
Copy link
Member

morozov commented Jun 5, 2021

If ORM is compatible with DBAL 3 before PHP 8.1.0 is out, we're fine I guess. That's the only blocker at the moment, isn't it?

I believe so, although I'm not an ORM maintainer or even a user. In any case, it would make more sense to channel the energy to improving the ORM rather than maintaining the 10-years old DBAL API.

@derrabus derrabus force-pushed the bugfix/return-type-will-change branch from 6d238fb to be9495a Compare June 5, 2021 22:06
@derrabus
Copy link
Member Author

derrabus commented Jun 5, 2021

I'm ignoring the broken sniff for now. This should yield us a green build.

greg0ire
greg0ire previously approved these changes Jun 6, 2021
SenseException
SenseException previously approved these changes Jun 6, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
marandaneto Manoel Aranda Neto
Signed-off-by: Alexander M. Turek <me@derrabus.de>
@derrabus derrabus dismissed stale reviews from SenseException and greg0ire via 268e75c June 7, 2021 15:37
@derrabus derrabus force-pushed the bugfix/return-type-will-change branch from be9495a to 268e75c Compare June 7, 2021 15:37
@derrabus
Copy link
Member Author

derrabus commented Jun 7, 2021

I've reverted the changes to the CodeSniffer configuration because slevomat/coding-standard#1233 has been fixed in the meantime.

@alcaeus alcaeus requested a review from greg0ire June 22, 2021 17:10
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@greg0ire greg0ire added this to the 2.13.3 milestone Jun 26, 2021
@greg0ire greg0ire merged commit fdf3cfd into doctrine:2.13.x Jun 26, 2021
@greg0ire
Copy link
Member

Thanks @derrabus !

@greg0ire
Copy link
Member

@morozov I added some labels, but I'm unsure this qualifies as a bug, feel free to add/remove some of them

@derrabus derrabus deleted the bugfix/return-type-will-change branch June 26, 2021 12:13
@morozov
Copy link
Member

morozov commented Jun 28, 2021

Note, this fails Psalm on PHP 8:

ERROR: UndefinedAttributeClass - lib/Doctrine/DBAL/Driver/PDOConnection.php:51:7 - Attribute class ReturnTypeWillChange does not exist (see https://psalm.dev/241)
    #[ReturnTypeWillChange]

And PHPStan:

 ------ ------------------------------------------------------ 
  Line   Doctrine/DBAL/Driver/PDOConnection.php                
 ------ ------------------------------------------------------ 
  51     Attribute class ReturnTypeWillChange does not exist.  

@derrabus
Copy link
Member Author

What would be your recommended course of action? imho, we can safely ignore those errors because defining attributes with an undefined class is a safe thing to do. Alternatively, we could add symfony/polyfill-php81 to the dev dependencies to make this class known.

@morozov
Copy link
Member

morozov commented Jun 28, 2021

Ignoring the errors in configuration is fine.

@derrabus
Copy link
Member Author

#4695

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants