From 74a211b10d61a707e44434f4540ef4b5fee31d5c Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 11 Mar 2023 22:29:36 +0000 Subject: [PATCH] ext/mysqli/pgsql: mysqli_fetch_object/pgsql_fetch_object raises ValueError on constructor args error. --- UPGRADING | 7 +++++++ ext/mysqli/mysqli.c | 3 +-- .../tests/mysqli_fetch_object_no_constructor.phpt | 10 +++++----- ext/pgsql/pgsql.c | 3 +-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/UPGRADING b/UPGRADING index 419fcf5919a29..de81b63dec5c6 100644 --- a/UPGRADING +++ b/UPGRADING @@ -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 diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index b42226a13f96c..f98ab2fc15f46 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -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) ); diff --git a/ext/mysqli/tests/mysqli_fetch_object_no_constructor.phpt b/ext/mysqli/tests/mysqli_fetch_object_no_constructor.phpt index 345eef6e28245..371299808ce25 100644 --- a/ext/mysqli/tests/mysqli_fetch_object_no_constructor.phpt +++ b/ext/mysqli/tests/mysqli_fetch_object_no_constructor.phpt @@ -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"); @@ -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!): diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 5157c0e6162ad..a2d6da12209b0 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -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) );