Skip to content

ext/mysqli/pgsql: mysqli_fetch_*/pgsql_fetch_* raises ValueError on c… #10832

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ PHP 8.3 UPGRADE NOTES
Underscores must be encoded as "=5F" in such MIME encoded words.
(Alex Dowad)

- mysqli:
. mysqli_fetch_object now raises a ValueError instead of an Exception when the constructor_args
argument is non empty with the class not having constructor.
- PGSQL:
. pg_fetch_object now raises a ValueError instead of an Exception when the constructor_args
argument is non empty with the class not having constructor.

- Standard:
. E_NOTICEs emitted by unserialized() have been promoted to E_WARNING.
RFC: https://wiki.php.net/rfc/improve_unserialize_error_handling
Expand Down
3 changes: 1 addition & 2 deletions ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
zend_call_known_function(ce->constructor, Z_OBJ_P(return_value), Z_OBJCE_P(return_value),
/* retval */ NULL, /* argc */ 0, /* params */ NULL, ctor_params);
} else if (ctor_params && zend_hash_num_elements(ctor_params) > 0) {
/* TODO Convert this to a ValueError */
zend_argument_error(zend_ce_exception, ERROR_ARG_POS(3),
zend_argument_value_error(ERROR_ARG_POS(3),
"must be empty when the specified class (%s) does not have a constructor",
ZSTR_VAL(ce->name)
);
Expand Down
10 changes: 5 additions & 5 deletions ext/mysqli/tests/mysqli_fetch_object_no_constructor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ require_once('skipifconnectfailure.inc');
printf("No exception with PHP:\n");
var_dump($obj = new mysqli_fetch_object_test(1, 2));

printf("\nException with mysqli. Note that at all other places we throws errors but no exceptions unless the error mode has been changed:\n");
printf("\nValueError with mysqli. Note that at all other places we throws errors but no exceptions unless the error mode has been changed:\n");
try {
var_dump($obj = mysqli_fetch_object($res, 'mysqli_fetch_object_test', array(1, 2)));
} catch (Exception $e) {
printf("Exception: %s\n", $e->getMessage());
} catch (ValueError $e) {
printf("ValueError: %s\n", $e->getMessage());
}

printf("\nFatal error with PHP (but no exception!):\n");
Expand All @@ -62,8 +62,8 @@ object(mysqli_fetch_object_test)#%d (%d) {
NULL
}

Exception with mysqli. Note that at all other places we throws errors but no exceptions unless the error mode has been changed:
Exception: mysqli_fetch_object(): Argument #3 ($constructor_args) must be empty when the specified class (mysqli_fetch_object_test) does not have a constructor
ValueError with mysqli. Note that at all other places we throws errors but no exceptions unless the error mode has been changed:
ValueError: mysqli_fetch_object(): Argument #3 ($constructor_args) must be empty when the specified class (mysqli_fetch_object_test) does not have a constructor

Fatal error with PHP (but no exception!):

Expand Down
3 changes: 1 addition & 2 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1847,8 +1847,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
zend_call_known_function(ce->constructor, Z_OBJ_P(return_value), Z_OBJCE_P(return_value),
/* retval */ NULL, /* argc */ 0, /* params */ NULL, ctor_params);
} else if (ctor_params && zend_hash_num_elements(ctor_params) > 0) {
/* TODO Convert this to a ValueError */
zend_argument_error(zend_ce_exception, 3,
zend_argument_value_error(3,
"must be empty when the specified class (%s) does not have a constructor",
ZSTR_VAL(ce->name)
);
Expand Down