-
-
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
Widen the return type of Result::rowCount()
#5879
Widen the return type of Result::rowCount()
#5879
Conversation
I realise I should have brought this up while reviewing #5274, but how widespread are 32 bit systems nowadays? I'm wondering if this is the right move. |
Okay, but we still support 32bit, do we. So let's assume we are on 32bit, use the MySQLi driver and execute a statement that affects 3G rows. What should we do?
|
There are 3 conditions, the likelihood of each seems low. I'm hesitating between throwing every time, and throwing on |
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.
Looks good code-wise. Not sure what to think about the overall move, it feels we're pandering to a corner case of a corner case of a corner case. I'd like to know what others think.
Yeah, I agree. Still, this PR is consistent with the rest of the codebase. If we want to revert the decision made in #5274, we need to pick one of the options in #5879 (comment) and fix all return types accordingly. |
I'm not aware about the general concerns or impact it may have, but from a distant point, I agree that a extreme corner case (ideally) should not push the library to relax types that at first sight seem the sanest and the right ones. |
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.
MySQLi and PHP_INT_MAX are two different things though, that are handled with the string
type. Supporting 32bit systems is similar like supporting old PHP versions that aren't supported anymore. I hope there aren't many servers out there being 32bit.
Triggering a warning with Adding |
No.
Our drivers don't have access to a logger, so not an option either.
Then don't? In what situations do you actually need this value to be an integer anyway? |
With what alternative?
People complain because their static analysis tool tells them to complain. I don't work complaint-driven; I need a good argument to revert those changes. How does that fact that the number of rows could be expressed as a numeric string actually impede anyone? Or in other words: What do you usually do with the row count?
So what actual problem do we solve by limiting the return type to integers again? |
An illustration of the type of code that I have to update: https://phpstan.org/r/7985f9bc-3d65-4b21-baa3-f29636645ff6 |
It's funny by the way that the static analysis tool can be silenced with an int cast here since integer + integer is not guaranteed to yield an integer. If the sum overflows, you'll still get a float. Also note that the row count returned here is more or less informational. Some drivers return |
None, to be frank. I mean I wouldn't write any code to handle this particular case, since we are not going to be able to test it. At best, I'd put a comment saying "If you get something else than an integer here, please report this at #5879 , you might win an iPad." |
That's basically the first option listed in #5879 (comment): A |
Oh right, I understood that as: let's provide a custom error message, but still throw a |
I feel like this is better discussed on an actual PR. I'm going to merge this one as it is consistent with previous changes to 4.0.x. Someone who wants to revert those types, please open a PR so we can discuss how we want to deal with MySQLi returning strings. But to be honest, I still think such change would only please static analyzers and not fix a real problem. |
Summary
We currently allow
Connection::exec()
to return the number of affected rows as a string, mainly to accommodate the MySQLi driver. However, we don't allowResult::rowCount()
orStatement::execute()
to do the same. Here we documentint
as native return type.In the scenario where MySQLi would report the number of rows as string, we would currently cause a type error because strict types are enabled on 4.0.
I realize that this change is painful for projects that run a static analyzer on code that interfaces with DBAL. However, we have decided that we want to leverage drivers that report large numbers of affected rows as strings for
Connection::exec()
and I believe we should be consistent about that throughout the API.