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

Restore PDOStatement::quote() for backward compatibility #4287

Merged
merged 1 commit into from Sep 24, 2020

Conversation

morozov
Copy link
Member

@morozov morozov commented Sep 22, 2020

Fixes #4281.

@morozov morozov added this to the 2.11.1 milestone Sep 22, 2020
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

The code looks good

well, int is a valid type according to the API

Is it really? I don't know what phpdoc we inherit but the signature says this should be a string: https://www.php.net/manual/en/pdo.quote.php

Also, it's a bit weird that PHPstan does not complain for this test… maybe it's a new rule, or maybe it's a level above the one we currently use.

@morozov
Copy link
Member Author

morozov commented Sep 23, 2020

Is it really? I don't know what phpdoc we inherit but the signature says this should be a string:

It is. This is the phpdoc PDOConnection inherits that says it's a mixed:

/**
* Quotes a string for use in a query.
*
* @param mixed $value
* @param int $type
*
* @return mixed
*/
public function quote($value, $type = ParameterType::STRING);

Take this code for example:

$conn = DriverManager::getConnection(
    'driver' => 'pdo_sqlite',
    'dbname' => 'sqlite::memory:',
)->getWrappedConnection();

For the caller, $conn above is just a Driver\Connection (which accepts mixed). The caller doesn't know that it's also a PDOConnection which extends PDO (which accepts string).

Furthermore, some other drivers explicitly handle the non-string values in quote():

public function quote($value, $type = ParameterType::STRING)
{
if (is_int($value) || is_float($value)) {
return $value;
}

Also, it's a bit weird that PHPstan does not complain for this test

We don't run PHPStan on tests in 2.x:

paths:
- %currentWorkingDirectory%/lib
reportUnmatchedIgnoredErrors: false

I tried enabling them quite some time ago and gave up because it was close to impossible w/o suppressing hundreds of errors or breaking BC. At that time, it wasn't clear that 2.x would be supported for that much longer.

Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

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

Since 2.10.x won't get this fix, this PR looks goot to me.

@greg0ire
Copy link
Member

Thanks for the explanation @morozov , very clear!

@greg0ire greg0ire merged commit 6ff72e4 into doctrine:2.11.x Sep 24, 2020
rgrellmann added a commit to Rossmann-IT/dbal that referenced this pull request Mar 7, 2021
Release [2.11.1](https://github.com/doctrine/dbal/milestone/80)

2.11.1
======

- Total issues resolved: **2**
- Total pull requests resolved: **8**
- Total contributors: **6**

Documentation
-------------

 - [4299: Link to contributing guide](doctrine#4299) thanks to @greg0ire

SQLite,Test Suite,pdo_sqlite
----------------------------

 - [4297: Fix ExceptionTest::testConnectionExceptionSqLite() on macOS](doctrine#4297) thanks to @morozov

 - [4296: Increase indent in definition lists](doctrine#4296) thanks to @greg0ire

Deprecation,Prepared Statements
-------------------------------

 - [4291: Deprecate Abstraction\Result](doctrine#4291) thanks to @morozov

BC Fix,Quoting
--------------

 - [4287: Restore PDOStatement::quote() for backward compatibility](doctrine#4287) thanks to @morozov and @Shahelm

BC Fix,Query
------------

 - [4286: Fix BC break: QueryBuilder::andWhere() etc. should ignore empty strings](doctrine#4286) thanks to @BenMorel and @infabo

Bug,Documentation,Prepared Statements
-------------------------------------

 - [4285: Fix phpdoc on deprecated functions](doctrine#4285) thanks to @qdequippe

Bug,PDO,Prepared Statements
---------------------------

 - [4173: Fix Third parameter not allowed for PDO::FETCH&doctrine#95;COLUMN](doctrine#4173) thanks to @BenMorel

# gpg: Signature made Sun Sep 27 06:35:40 2020
# gpg:                using DSA key 1BEDEE0A820BC30D858F9F0C2C3A645671828132
# gpg: Can't check signature: No public key
@morozov morozov deleted the issues/4281 branch February 23, 2022 02:57
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2023
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.

BC Break after removing method \Doctrine\DBAL\Driver\PDOConnection::quote
3 participants