Skip to content

Commit 5a8ac73

Browse files
committed
ext/mysqli/pgsql: mysqli_fetch_object/pgsql_fetch_object raises ValueError on constructor args
error.
1 parent 5c058d7 commit 5a8ac73

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

UPGRADING

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ PHP 8.3 UPGRADE NOTES
9292
Underscores must be encoded as "=5F" in such MIME encoded words.
9393
(Alex Dowad)
9494

95+
- mysqli:
96+
. mysqli_fetch_object raises a ValueError when the constructor_args argument
97+
is non empty with the class not having constructor.
98+
99+
- PGSQL:
100+
. pg_fetch_object raises a ValueError when the constructor_args argument
101+
is non empty with the class not having constructor.
102+
95103
- Standard:
96104
. E_NOTICEs emitted by unserialized() have been promoted to E_WARNING.
97105
RFC: https://wiki.php.net/rfc/improve_unserialize_error_handling

ext/mysqli/mysqli.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
805805
zend_call_known_function(ce->constructor, Z_OBJ_P(return_value), Z_OBJCE_P(return_value),
806806
/* retval */ NULL, /* argc */ 0, /* params */ NULL, ctor_params);
807807
} else if (ctor_params && zend_hash_num_elements(ctor_params) > 0) {
808-
/* TODO Convert this to a ValueError */
809-
zend_argument_error(zend_ce_exception, ERROR_ARG_POS(3),
808+
zend_argument_value_error(ERROR_ARG_POS(3),
810809
"must be empty when the specified class (%s) does not have a constructor",
811810
ZSTR_VAL(ce->name)
812811
);

ext/mysqli/tests/mysqli_fetch_object_no_constructor.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ require_once('skipifconnectfailure.inc');
3232
printf("No exception with PHP:\n");
3333
var_dump($obj = new mysqli_fetch_object_test(1, 2));
3434

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

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

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

6868
Fatal error with PHP (but no exception!):
6969

ext/pgsql/pgsql.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,8 +1847,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
18471847
zend_call_known_function(ce->constructor, Z_OBJ_P(return_value), Z_OBJCE_P(return_value),
18481848
/* retval */ NULL, /* argc */ 0, /* params */ NULL, ctor_params);
18491849
} else if (ctor_params && zend_hash_num_elements(ctor_params) > 0) {
1850-
/* TODO Convert this to a ValueError */
1851-
zend_argument_error(zend_ce_exception, 3,
1850+
zend_argument_value_error(3,
18521851
"must be empty when the specified class (%s) does not have a constructor",
18531852
ZSTR_VAL(ce->name)
18541853
);

0 commit comments

Comments
 (0)