-
Notifications
You must be signed in to change notification settings - Fork 188
[Core: Database] Add exception on fetchAll failure case #3880
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
Conversation
php/libraries/Database.class.inc
Outdated
| // The fetchAll function will return an empty set if no results are | ||
| // found and FALSE on "failure". We don't expect this case so an | ||
| // exception is thrown. | ||
| if (is_bool($rows)) { |
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 isn't checking if it's false, it's checking if it's a boolean. It should be === false
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.
I tried that at first but phan gave me an error about comparing an array to a boolean (in the case where it was NOT false).
I'll change this statement to include both and see how phan feels about it.
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 docs pretty clearly say that the return type is array|false, so if phan is complaining about checking the false case it sounds like a bug in phan.
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.
How about !is_array() ?
xlecours
left a comment
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.
I think that this highlights the fact that the Database::execute function is doing more than just one thing.
|
@xlecours Yeah a lot of the DB functions return many many different types which makes validation and use of them kinda tricky. This is one small step in the process.... |
Brief summary of changes
In an effort to take advantage of PHP's type system, we should add type declarations to our code, especially in the core classes.
The PDO documentation says that
fetchAllreturns the empty set when no data in the DB matches a given query and FALSE on failure. However we do not distinguish this in our codebase and so a FALSE value is allowed to bubble up through subsequent DB calls.This makes it so that these functions must sometimes return the Bool type (in addition to String, Array, and Null) meaning we cannot use return type declarations.
Following a discussion in #3854, this PR adds an exception when the
fetchAllclass fails. This will allow us to remove Bool as one of the return types.This is likely to break some things (I found it by debugging a failing test in #3878) so it is issued to
major.Related issues