Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add polyfill for PDO driver specific subclasses#549

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jnoordsij wants to merge12 commits intosymfony:1.x
base:1.x
Choose a base branch
Loading
fromjnoordsij:add-pdo-subdriver-constant-polyfill

Conversation

@jnoordsij
Copy link

As a follow-up to#547, this PR aims to implement a full-fledged set of polyfills for the driver specific PDO subclasses introduced in PHP 8.4; see alsohttps://wiki.php.net/rfc/pdo_driver_specific_subclasses.

As of PHP 8.5, the driver specific constants and methods available on the basePDO class will be deprecated, to be removed in PHP 9.0. See alsohttps://wiki.php.net/rfc/deprecations_php_8_5#deprecate_driver_specific_pdo_constants_and_methods.

This PR adds a polyfill to use the driver-specific child classes for PHP versions prior to PHP 8.4. This in turn allows one to already refer to the 'new' constant, to prevent deprecation errors on PHP 8.5, while retaining backwards compatibility. This can be particularly useful for code requiring support for multiple versions; see e.g.laravel/framework#57141.

The classes should be suitable for constructing on older PHP versions.

Note thePDO::connect static method that has been introduced simultaneously has not been polyfilled, as I can't think of a proper way to do such a thing currently.

gabrielrbarbosa, mostafaznv, and mitelg reacted with thumbs up emoji
@jnoordsijjnoordsij marked this pull request as draftOctober 16, 2025 12:51
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Should we add the static connect method to every child class, since we can polyfill it there?
How does this method behave when given a DSN for another driver and when it's called on a child class?

@jnoordsijjnoordsijforce-pushed theadd-pdo-subdriver-constant-polyfill branch from325af09 tof0b0b10CompareOctober 16, 2025 12:57
@jnoordsij
Copy link
Author

Should we add the static connect method to every child class, since we can polyfill it there? How does this method behave when given a DSN for another driver and when it's called on a child class?

We could, but that feels a bit off to me. The whole idea of thePDO::connect static method is that it is able to detect the type of driver and thus subclass to use from the provided dsn, making it generic. Calling e.g.\Pdo\Mysqlite::connect(...) instead of justnew \Pdo\Mysqlite(...) makes little sense to me, and probably should not be something to actively encourage in any userland code?

@nicolas-grekas
Copy link
Member

About the connect method on child classes, I'd still add it, for completness of the polyfill

jnoordsij and mostafaznv reacted with thumbs up emoji

@jnoordsijjnoordsijforce-pushed theadd-pdo-subdriver-constant-polyfill branch from97852db to8034458CompareOctober 16, 2025 13:48
@jnoordsij
Copy link
Author

I probably will look into the last bits next week; if anyone is eager to finalize on theconnect method or think of additional tests to throw in here, feel free to add them.

nicolas-grekas reacted with thumbs up emoji

@derrabus
Copy link
Member

derrabus commentedOct 16, 2025
edited
Loading

Calling e.g.\Pdo\Mysqlite::connect(...) instead of justnew \Pdo\Mysqlite(...) makes little sense to me, and probably should not be something to actively encourage in any userland code?

But if you are on PHP 8.4, would you really call the constructor of those subclasses instead ofPDO::connect()? So either way, we're encouraging userland code that is different with the polyfill than with the real thing, mainly because we cannot polyfillPDO::connect(). 😕

@jnoordsijjnoordsijforce-pushed theadd-pdo-subdriver-constant-polyfill branch from8034458 toa89fdfeCompareOctober 20, 2025 08:58
@jnoordsij
Copy link
Author

jnoordsij commentedOct 20, 2025
edited
Loading

But if you are on PHP 8.4, would you really call the constructor of those subclasses instead ofPDO::connect()? So either way, we're encouraging userland code that is different with the polyfill than with the real thing, mainly because we cannot polyfillPDO::connect(). 😕

To be fair, if one is currently only using something likenew PDO("sqlite:foo");, then migrating towardsnew Pdo\Sqlite("sqlite:foo"); does not seem like a weird strategy to me. In particular for projects were the driver class is already predetermined and you want to have the added benefit of stricter types for static analysis, one could prefer this overPDO::connect which will from a static point of view only ever returnPDO. However I do agree that the main usecase would still be to usedPDO::connect, which unfortunately is not something we can provide.

@jnoordsijjnoordsij marked this pull request as ready for reviewOctober 20, 2025 09:10
@jnoordsijjnoordsijforce-pushed theadd-pdo-subdriver-constant-polyfill branch fromecd99c0 tof42017aCompareOctober 20, 2025 09:16
@jnoordsij
Copy link
Author

I think this should be complete now as is. Additional feature-like tests could be nice, but on the other hand are probably very hard to implement in practice without any real database and I think the current set should suffice to prove this should work in practice. In particular the migration towards 'polyfilled' constants should be very safe to do with this.

gabrielrbarbosa reacted with thumbs up emoji

@jnoordsij
Copy link
Author

@nicolas-grekas with PHP 8.5 stable coming up next week, is there any chance of aiming to review and release this somewhere within that timeframe?

mostafaznv reacted with thumbs up emoji

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Can you please proceed with these CS changes on all classes?

Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
@jnoordsijjnoordsijforce-pushed theadd-pdo-subdriver-constant-polyfill branch frome04dc06 to62b8a86CompareNovember 12, 2025 10:36
@jnoordsij
Copy link
Author

Can you please proceed with these CS changes on all classes?

Done!

IonBazan, crynobone, and mostafaznv reacted with rocket emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasAwaiting requested review from nicolas-grekas

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@jnoordsij@nicolas-grekas@derrabus

[8]ページ先頭

©2009-2025 Movatter.jp