Skip to content

Commit 974a3d8

Browse files
committed
ext/mysqli/pgsql: mysqli_fetch_object/pgsql_fetch_object raises ValueError on constructor args error.
Closes GH-10832.
1 parent f9375dc commit 974a3d8

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ PHP NEWS
7474
Underscores must be encoded as "=5F" in such MIME encoded words.
7575
(Alex Dowad)
7676

77+
- mysqli:
78+
. mysqli_fetch_object raises a ValueError instead of an Exception.
79+
(David Carlier)
80+
7781
- Opcache:
7882
. Added start, restart and force restart time to opcache's
7983
phpinfo section. (Mikhail Galanin)
@@ -90,6 +94,10 @@ PHP NEWS
9094
. SA_ONSTACK is now set for pcntl_signal. (Kévin Dunglas)
9195
. Added SIGINFO constant. (David Carlier)
9296

97+
- PGSQL:
98+
. pg_fetch_object raises a ValueError instead of an Exception.
99+
(David Carlier)
100+
93101
- Posix:
94102
. Added posix_sysconf. (David Carlier)
95103
. Added posix_pathconf. (David Carlier)

UPGRADING

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ 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 now raises a ValueError instead of an Exception when the constructor_args
97+
argument is non empty with the class not having constructor.
98+
- PGSQL:
99+
. pg_fetch_object now raises a ValueError instead of an Exception when the constructor_args
100+
argument is non empty with the class not having constructor.
101+
95102
- Standard:
96103
. E_NOTICEs emitted by unserialized() have been promoted to E_WARNING.
97104
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)