Skip to content

Conversation

@arshidkv12
Copy link

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

From what I can see (as somebody who doesn't maintain this code), most arguments are validated without the MYSQLI_REPORT_ERROR guard, and throw a zend_argument_value_error().

But somebody who does maintain this should confirm.

arshidkv12 and others added 3 commits January 19, 2026 21:33
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
@arshidkv12
Copy link
Author

From what I can see (as somebody who doesn't maintain this code), most arguments are validated without the MYSQLI_REPORT_ERROR guard, and throw a zend_argument_value_error().

But somebody who does maintain this should confirm.

- if (MyG(report_mode) & MYSQLI_REPORT_ERROR) {
	zend_value_error("mysqli_options(): Invalid option %d", (int)mysql_option);

Do we need to remove if (MyG(report_mode) & MYSQLI_REPORT_ERROR)? What do you think?

@arshidkv12 arshidkv12 requested a review from iluuu1994 January 19, 2026 16:50
@iluuu1994
Copy link
Member

Somebody else should review this. /cc @Girgias @SakiTakamachi

@kamil-tekiela
Copy link
Member

First of all, I don't know if this should be an error condition. I guess it kind of makes sense. But as you can see in the test, no message was the behaviour by design.

The error should be without the guard and without the function name in the message. It seems to me like you have also put it in the wrong place. Judging by the message and the test, you wanted to put it in the switch statement after that.

The message isn't very descriptive either. What does it mean "invalid option"? What should the user do differently?

@arshidkv12
Copy link
Author

Changed the error message to zend_value_error("Argument #1 ($option) is not a valid mysqli option");

arshidkv12 and others added 4 commits January 20, 2026 18:59
Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
@arshidkv12
Copy link
Author

Thank you @kamil-tekiela kamil-tekiela

@kamil-tekiela
Copy link
Member

@iluuu1994 Are you ok with how this looks now?

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

I'm not a codeowner, but yes, LGTM now. Thanks @arshidkv12!

@@ -0,0 +1,27 @@
--TEST--
Bug #20968 mysqli_options() with invalid option triggers ValueError
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Bug #20968 mysqli_options() with invalid option triggers ValueError
GH-20968 mysqli_options() with invalid option triggers ValueError

We use Bug #xxxxx notation to refer to old bugsnet bugs.


$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket);

$value = $mysqli->options(10, 'invalid_option');
Copy link
Member

Choose a reason for hiding this comment

The 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.

Comment on lines 1200 to +1204
expected_type = mysqli_options_get_option_zval_type(mysql_option);
if (expected_type == IS_NULL) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of predefined options");
RETURN_THROWS();
}
Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

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.

@@ -0,0 +1,27 @@
--TEST--
Bug #20968 mysqli_options() with invalid option triggers ValueError
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Bug #20968 mysqli_options() with invalid option triggers ValueError
Bug #20968 mysqli_options() with invalid option should triggers ValueError

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants