-
Notifications
You must be signed in to change notification settings - Fork 8k
Mysqli: fix missing error for invalid mysqli_options() option #20971
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
base: master
Are you sure you want to change the base?
Changes from all commits
a401699
217b19b
66fbc0a
54a8e06
0716f97
d7dd938
1aa360a
04f8006
9ba4bf2
2db6e98
29ed278
1647ae8
0a98c9c
8193542
3a633b3
072d1a4
a188868
e102967
6a71d4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,27 @@ | ||||||||||
| --TEST-- | ||||||||||
| Bug #20968 mysqli_options() with invalid option triggers ValueError | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We use Bug #xxxxx notation to refer to old bugsnet bugs.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The phrasing of the bug title seems to imply that an invalid option MUST NOT thow a ValueError, which is the complete opposite of what is being done. |
||||||||||
| --EXTENSIONS-- | ||||||||||
| mysqli | ||||||||||
| --CONFLICTS-- | ||||||||||
| mysqli | ||||||||||
| --SKIPIF-- | ||||||||||
| <?php | ||||||||||
| require_once 'skipifconnectfailure.inc'; | ||||||||||
| ?> | ||||||||||
| --FILE-- | ||||||||||
| <?php | ||||||||||
| require_once 'connect.inc'; | ||||||||||
|
|
||||||||||
| $mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket); | ||||||||||
|
|
||||||||||
| $value = $mysqli->options(10, 'invalid_option'); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a try catch here and check the exception message, we don't care about the stack trace. |
||||||||||
|
|
||||||||||
| var_dump($value); | ||||||||||
|
|
||||||||||
| ?> | ||||||||||
| --EXPECTF-- | ||||||||||
| Fatal error: Uncaught ValueError: mysqli::options(): Argument #1 ($option) must be one of predefined options in %s:%d | ||||||||||
| Stack trace: | ||||||||||
| #0 %s(%d): mysqli->options(%d, 'invalid_option') | ||||||||||
| #1 {main} | ||||||||||
| thrown in %s on line %d | ||||||||||
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.
We normally list the available options, and if there are too many we at least provide a prefix for the error eg. MYSQLI_BLAH_X
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 thought about that too, but there isn't any common pattern between them. One of the values doesn't even have a corresponding constants.
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.
That seems kinda bad that one of the options doesn't have a constant?
As future scope, would it make sense to have an Enum of MySQLi options? As that would make the type checking and value validation easy.
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.
Yes, it is. Maybe we should add the constant. Enums would definitely be better but it would be a breaking change difficult for cross-version compatibilty.
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.
It would be possible to assign the enum case as the constant value, or support int|Enum. But I think already adding the missing constant is the big thing.