[11.x] Add PDO subclass support for PHP 8.4 #52538
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In PHP 8.4 there will be PDO driver specific subclasses. PHP will introduce classes for each database driver it supports. It allows for driver specific methods. I don't think this will be a huge improvement for most, but it does allow SQLite users to load extensions for example. This is not available in PDO at the moment.
If you're not using Laravel this would look like this:
I'm not sure what your policy is for features that are only in 8.4, so please let me know what I could do to improve on this. I've targeted this at 11.x as it's backwards compatible with older PHP versions.
Backwards compatibility
PDO::connect
returns a subclass of PDO. It will pick the correct subclass for you based on the DSN. As the subclass extends PDO, the return type does not need to change and is backwards compatible.As
PDO::connect
is not compatible with versions prior to 8.4. This PR is backwards compatible by usingnew PDO
for other PHP versions instead.Tests
I haven't included any new tests.
PDO::connect
is a PHP function so it should not require testing in userland. The method itself is already covered by the test suite and its functionality remains the same.Edit: static analysis failed because it runs on 8.2 where
PDO::connect
does not exist yet.References