Skip to content
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

Add $statement parameter to PDOConnection::query() #3770

Closed
wants to merge 1 commit into from

Conversation

nikic
Copy link

@nikic nikic commented Dec 5, 2019

Q A
Type bug-ish
BC Break no
Fixed issues

Summary

PHP 8 updates the signature to PDO::query(string $statement), so change PDOConnection to be compatible with that (but also older versions).

This doesn't seem relevant for version 3.x anymore (which does not extend PDO), but this should allow testing current Symfony and Laravel versions under PHP 8.

PHP 8 updates the signature to `PDO::query(string $statement)`, so change `PDOConnection` to be compatible with that (but also older versions).

This doesn't seem relevant for version 3.x anymore (which does not extend PDO), but this should allow testing current Symfony and Laravel versions under PHP 8.
@morozov
Copy link
Member

morozov commented Dec 5, 2019

Thank you @nikic for the patch. The 2.10 version accepts only bug fixes while this is not really a bug. The target branch for new features and improvements is master but it doesn't need this patch.

Given that the timelines of neither of Doctrine DBAL 3.0 and PHP 8.0 are clear, I'm not sure where exactly this patch should land.

@doctrine/team-dbal,

If we want to support PHP 8 in DBAL 2.x, we should create a new minor branch (2.11) and retarget the patch there. Not supporting PHP 8 in DBAL 2.x will make users go through a significant BC break in DBAL 3.0 to be able to use PHP 8 (which will also contain BC breaks). That might be too much.

@morozov
Copy link
Member

morozov commented Dec 5, 2019

Additionally, it seems to be not the only issue that prevents testing DBAL 2.10 on PHP 8:

$ phpunit
PHPUnit 8.4.1 by Sebastian Bergmann and contributors.

......................
Fatal error: Declaration of Doctrine\DBAL\Driver\PDOStatement::setFetchMode($fetchMode, $arg2 = NULL, $arg3 = NULL) must be compatible with PDOStatement::setFetchMode(int $mode, ...$params) in /home/morozov/Projects/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php on line 50

Not sure how this one could be fixed to be compatible with both PHP 7 and PHP 8 without causing a BC break.

On the contrary, the test results on the master branch look much better:

$ phpunit
PHPUnit 8.4.1 by Sebastian Bergmann and contributors.

...................................................................SSS.......   77 / 3864 (  1%)
.....................................................................SS......  154 / 3864 (  3%)
.....................................S.................SS..S.SS.FF.......SSSS  231 / 3864 (  5%)
SSSSSSSSSSSSSSSSS............................................................  308 / 3864 (  7%)
.............SSSS.........S..................................................  385 / 3864 (  9%)
.............................................................................  462 / 3864 ( 11%)
..SSSSSSSSSSSSSSSS.....SSSSSSSSSSSSSS.SSSSSSSSSSSSS...SSSS......SSS..S.SSSSSS  539 / 3864 ( 13%)
SSS.......................S.....................SSSSSSSSSSSSSSSSSSSSSSSSSSSSS  616 / 3864 ( 15%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSS..................................SSSSSSSSSSSSSSS  693 / 3864 ( 17%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS  770 / 3864 ( 19%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS  847 / 3864 ( 21%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS  924 / 3864 ( 23%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 1001 / 3864 ( 25%)
SSSSSSSSSSSSSSS................SSS........SS..S...SS.....S.S...........SS.... 1078 / 3864 ( 27%)
..SS.S.......................SSSS..SSS.SSSSSSSSSS...........................S 1155 / 3864 ( 29%)
S............................................................................ 1232 / 3864 ( 31%)
..................................................I........SSS............... 1309 / 3864 ( 33%)
........S.................................................................... 1386 / 3864 ( 35%)
......................................................................S...... 1463 / 3864 ( 37%)
............................................................................. 1540 / 3864 ( 39%)
............................................................................. 1617 / 3864 ( 41%)
.S........................................................................... 1694 / 3864 ( 43%)
............................................................................. 1771 / 3864 ( 45%)
........S.................................................................... 1848 / 3864 ( 47%)
............................................................................. 1925 / 3864 ( 49%)
................I........SSS................................................. 2002 / 3864 ( 51%)
............................................................................. 2079 / 3864 ( 53%)
........................................................................SSS.. 2156 / 3864 ( 55%)
............................................................................. 2233 / 3864 ( 57%)
............................................................................. 2310 / 3864 ( 59%)
.........................................SSS................................. 2387 / 3864 ( 61%)
.................................................S........................... 2464 / 3864 ( 63%)
.......................................................................I..... 2541 / 3864 ( 65%)
...SSS....................................................................... 2618 / 3864 ( 67%)
............................................................................. 2695 / 3864 ( 69%)
..............................I........SSS................................... 2772 / 3864 ( 71%)
............................................................................. 2849 / 3864 ( 73%)
...................................................................I........S 2926 / 3864 ( 75%)
SS........................................II................................. 3003 / 3864 ( 77%)
............................SSS..............................S........S...... 3080 / 3864 ( 79%)
............................................................................. 3157 / 3864 ( 81%)
............................................................................. 3234 / 3864 ( 83%)
............................................................................. 3311 / 3864 ( 85%)
...............................S............................................. 3388 / 3864 ( 87%)
............................................................................. 3465 / 3864 ( 89%)
............................................................................. 3542 / 3864 ( 91%)
............................................................................. 3619 / 3864 ( 93%)
............................................................................. 3696 / 3864 ( 95%)
............................................................................. 3773 / 3864 ( 97%)
............................................................................. 3850 / 3864 ( 99%)
..............                                                                3864 / 3864 (100%)

Time: 1.04 seconds, Memory: 66.00 MB

There were 2 failures:

1) Doctrine\Tests\DBAL\Driver\OCI8\OCI8StatementTest::testExecute with data set #0 (array('test', null, 'value'))
Failed asserting that exception of type "TypeError" matches expected exception "Doctrine\DBAL\Driver\OCI8\OCI8Exception". Message was: "oci_execute(): supplied resource is not a valid oci8 statement resource" at
/home/morozov/Projects/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php:361
/home/morozov/Projects/dbal/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php:74
.

2) Doctrine\Tests\DBAL\Driver\OCI8\OCI8StatementTest::testExecute with data set #1 (array(null, 'test', 'value'))
Failed asserting that exception of type "TypeError" matches expected exception "Doctrine\DBAL\Driver\OCI8\OCI8Exception". Message was: "oci_execute(): supplied resource is not a valid oci8 statement resource" at
/home/morozov/Projects/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php:361
/home/morozov/Projects/dbal/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php:74
.

FAILURES!
Tests: 3864, Assertions: 6215, Failures: 2, Skipped: 559, Incomplete: 7.

@nikic
Copy link
Author

nikic commented Dec 6, 2019

@morozov Thanks for pointing that out, I went ahead and reverted that particular change: php/php-src@4a5e17f I remember there's some trick to being compatible with both signatures, but in this particular case the change wasn't really intentional, just that nobody checked that it's compatible with earlier versions...

@greg0ire
Copy link
Member

greg0ire commented Dec 6, 2019

This change is a BC-break for extending classes: https://3v4l.org/RQ20D

That said, if 3.0 is too much of a BC-break for users that just want php 8, maybe we should release 3.0 or event part of it earlier?

@morozov
Copy link
Member

morozov commented Dec 6, 2019

On a build from php/php-src@1d69bf1, this PR looks better:

$ phpunit --verbose
PHPUnit 8.4.1 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.0.0-dev
Configuration: /home/morozov/Projects/dbal/phpunit.xml.dist

..................................................................SSS....   73 / 5603 (  1%)
.........................................................................  146 / 5603 (  2%)
...SS.............................................S...................SS.  219 / 5603 (  3%)
..S.......................................................S.SSS..........  292 / 5603 (  5%)
..................................................SS.................SS..  365 / 5603 (  6%)
SSSSSS......SSS..........................................................  438 / 5603 (  7%)
...................SS...SSS................................SS...S........  511 / 5603 (  9%)
........................S.S.....S........................................  584 / 5603 ( 10%)
...........................SSSS..........................................  657 / 5603 ( 11%)
...............................................SSSSSSSSSSSSSSSSS.....SSSS  730 / 5603 ( 13%)
SSSSSSSSS..SSSSSSSSSSSSS...SSSS......SSS..S.SSSSSSSSS....................  803 / 5603 ( 14%)
...S.....................SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS  876 / 5603 ( 15%)
SSSSSSSSSSSSSS..................................SSSSSSSSSSSSSSSSSSSSSSSSS  949 / 5603 ( 16%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 1022 / 5603 ( 18%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 1095 / 5603 ( 19%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 1168 / 5603 ( 20%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 1241 / 5603 ( 22%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 1314 / 5603 ( 23%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS................SSS........SS..S...SS 1387 / 5603 ( 24%)
.....S.S...........S..SSSS......SS.S.....................SS..SSS...SSSSSS 1460 / 5603 ( 26%)
SSSS.S...........................SS...................................... 1533 / 5603 ( 27%)
......................................................................... 1606 / 5603 ( 28%)
............I........SSS.......................S......................... 1679 / 5603 ( 29%)
......................................................................... 1752 / 5603 ( 31%)
......................................S.................................. 1825 / 5603 ( 32%)
......................................................................... 1898 / 5603 ( 33%)
....................................................S.................... 1971 / 5603 ( 35%)
......................................................................... 2044 / 5603 ( 36%)
.................................................................S....... 2117 / 5603 ( 37%)
......................................................................... 2190 / 5603 ( 39%)
......................................................................... 2263 / 5603 ( 40%)
......I........SSS....................................................... 2336 / 5603 ( 41%)
......................................................................... 2409 / 5603 ( 42%)
..............................................................S.......... 2482 / 5603 ( 44%)
..SSS.................................................................... 2555 / 5603 ( 45%)
......................................................................... 2628 / 5603 ( 46%)
................................................S.............SSS........ 2701 / 5603 ( 48%)
......................................................................... 2774 / 5603 ( 49%)
......................................................................... 2847 / 5603 ( 50%)
...................................S............SSS...................... 2920 / 5603 ( 52%)
......................................................................... 2993 / 5603 ( 53%)
......................................................................... 3066 / 5603 ( 54%)
.....................S............SSS.................................... 3139 / 5603 ( 56%)
......................................................................... 3212 / 5603 ( 57%)
......................................................................... 3285 / 5603 ( 58%)
.....S.............SSS......................S............................ 3358 / 5603 ( 59%)
......................................................................... 3431 / 5603 ( 61%)
......................................................I........SSS....... 3504 / 5603 ( 62%)
.............S......S.................................................... 3577 / 5603 ( 63%)
......................................................................... 3650 / 5603 ( 65%)
...........................I........SSS......................S.....S..... 3723 / 5603 ( 66%)
......................................................................... 3796 / 5603 ( 67%)
......................................................................... 3869 / 5603 ( 69%)
.I........SSS............................................................ 3942 / 5603 ( 70%)
......................................................................... 4015 / 5603 ( 71%)
..........................................I........SSS................... 4088 / 5603 ( 72%)
......................................................................... 4161 / 5603 ( 74%)
......................................................................... 4234 / 5603 ( 75%)
.....I........SSS........................................................ 4307 / 5603 ( 76%)
......................................................................... 4380 / 5603 ( 78%)
..............................................I........SSS............... 4453 / 5603 ( 79%)
...........................S......S..S.S................................. 4526 / 5603 ( 80%)
......................................................................... 4599 / 5603 ( 82%)
................I........SSS..........................................II. 4672 / 5603 ( 83%)
.............................................................SSS......... 4745 / 5603 ( 84%)
..........S.....S........S............................................... 4818 / 5603 ( 85%)
......................................................................... 4891 / 5603 ( 87%)
......................................................................... 4964 / 5603 ( 88%)
......................................................................... 5037 / 5603 ( 89%)
.S....................................................................... 5110 / 5603 ( 91%)
......................................................................... 5183 / 5603 ( 92%)
......................................................................... 5256 / 5603 ( 93%)
......................S..SSS............................................. 5329 / 5603 ( 95%)
......................................................................... 5402 / 5603 ( 96%)
......................................................................... 5475 / 5603 ( 97%)
......................................................................... 5548 / 5603 ( 99%)
.......................................................                   5603 / 5603 (100%)

Time: 1.04 seconds, Memory: 78.00 MB

OK, but incomplete, skipped, or risky tests!
Tests: 5603, Assertions: 9776, Skipped: 697, Incomplete: 11.

Although, the @greg0ire's concern still stands.

@nikic
Copy link
Author

nikic commented Dec 26, 2019

Any ideas on how to move forward here? On the PHP side, we could avoid the compat-issue with Doctrine by removing the parameter, but that would break other code that (correctly) does specify the parameter. This method fell into a crack where the signature was not checked at all, so both variants are currently silently accepted and we need to pick one.

@morozov
Copy link
Member

morozov commented Dec 26, 2019

A BC break for extending classes doesn't look like to much harm compared to the benefit of being able to use PHP 8. As far as I understand, after adding the optional parameter, the extending class be compatible with the older and newer DBAL 2.x versions.

I'm personally not aware of any specific projects that would be impacted by this change. AFAIK @nikic has some setup for scanning most popular PHP packages for compatibility with the changes made to PHP. Would it be possible to do the same and find the classes that override Doctrine\DBAL\Driver\PDOConnection::query()?

In addition, we could have a twitter poll (link).

@greg0ire
Copy link
Member

Is there a plan for making classes final in 3.0? Maybe this could be an occasion to deter people from extending the class by marking it with @final, and encourage them to use composition instead?

@morozov
Copy link
Member

morozov commented Dec 29, 2019

There is a plan to make some classes final in 3.0 (#3585). Although, this specific class is not on the list of autodetected classes. We need to see what else API it exposes beyond the methods defined in the interface.

@greg0ire
Copy link
Member

greg0ire commented Dec 30, 2019

Alternatively to moving towards final, we may just deprecate not having that parameter in an extending class, by doing the \func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface dance

@morozov
Copy link
Member

morozov commented Dec 30, 2019

@greg0ire I'd rather branch and later release 3.0 that uncouples our API from PDO as suggested in #3770 (comment). So far, despite tons of conflicts, the end result looks clean: #3798.

@morozov
Copy link
Member

morozov commented Jan 8, 2020

Closed in favor of #3803.

@morozov morozov closed this Jan 8, 2020
@morozov morozov self-assigned this Jan 8, 2020
@morozov
Copy link
Member

morozov commented Apr 20, 2020

@nikic FWIW, the revert made in php/php-src@4a5e17f is no longer relevant for DBAL 3 since our classes will no longer extend the PDO's ones. Unless there are other widely used solutions that extend it, it might make sense to restore the variadic arguments. Even then it would be a good example of why developers should not tightly couple their code to the APIs they don't own in the form of class inheritance.

craigh referenced this pull request in zikula/core Jan 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 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.

3 participants