-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Clearer Connection return types for affectedRows #5334
Conversation
Found some problems in PHPStan fixed in phpstan/phpstan-src#1116 - similar issues are present in Psalm still but I'd rather not waste more time if this change isn't going to be accepted, so waiting for feedback first. |
$count = $this->connection->affected_rows; | ||
|
||
if (is_string($count)) { | ||
$count = PHP_INT_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is by no means acceptable. The library must not alter the data returned by the underlying driver in order to fit it into its own API which is incorrectly defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the alternative? Right now, if the number of affected rows is larger than PHP_INT_MAX
and thus returned as a string by ext-mysqli
, we will run into a TypeError
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type should be int|string
as it is in 4.0.x
:
dbal/src/Driver/Mysqli/Connection.php
Line 60 in 8622d1d
public function exec(string $sql): int|string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, but don't we need a solution for DBAL 3 as well? After all, this is our maintained branch. Raising type errors seems like a mistake to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in #5317 (comment), it seems acceptable to remove the int
return type declaration in 3.x
since it's invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's do that.
Summary
Per
dbal/src/Connection.php
Lines 1157 to 1160 in 83f779b