Skip to content

Commit 145207c

Browse files
committed
ext/mysqli/pgsql: mysqli_fetch_*/pgsql_fetch_* raises ValueError on constructor args
error.
1 parent 5c058d7 commit 145207c

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

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)