Skip to content

Commit 5bf01fc

Browse files
committed
Use the default type error message for Exception::__construct()
Closes GH-5460
1 parent d7f7080 commit 5bf01fc

File tree

6 files changed

+7
-28
lines changed

6 files changed

+7
-28
lines changed

Zend/tests/exception_018.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ throw new Hello(new stdClass);
88

99
?>
1010
--EXPECTF--
11-
Fatal error: Uncaught Error: Wrong parameters for Hello([string $message [, long $code [, Throwable $previous = NULL]]]) in %sexception_018.php:%d
11+
Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
1212
Stack trace:
1313
#0 %sexception_018.php(%d): Exception->__construct(Object(stdClass))
1414
#1 {main}

Zend/tests/exception_019.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ throw new Exception(new stdClass);
77

88
?>
99
--EXPECTF--
10-
Fatal error: Uncaught Error: Wrong parameters for Exception([string $message [, long $code [, Throwable $previous = NULL]]]) in %sexception_019.php:%d
10+
Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
1111
Stack trace:
1212
#0 %sexception_019.php(%d): Exception->__construct(Object(stdClass))
1313
#1 {main}

Zend/tests/exception_020.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ throw new MyErrorException(new stdClass);
88

99
?>
1010
--EXPECTF--
11-
Fatal error: Uncaught Error: Wrong parameters for MyErrorException([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Throwable $previous = NULL]]]]]]) in %sexception_020.php:%d
11+
Fatal error: Uncaught TypeError: ErrorException::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
1212
Stack trace:
1313
#0 %sexception_020.php(%d): ErrorException->__construct(Object(stdClass))
1414
#1 {main}

Zend/tests/exception_021.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ throw new Hello(new stdClass);
88

99
?>
1010
--EXPECTF--
11-
Fatal error: Uncaught Error: Wrong parameters for Hello([string $message [, long $code [, Throwable $previous = NULL]]]) in %sexception_021.php:%d
11+
Fatal error: Uncaught TypeError: Error::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
1212
Stack trace:
1313
#0 %sexception_021.php(%d): Error->__construct(Object(stdClass))
1414
#1 {main}

Zend/tests/exception_022.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ throw new Error(new stdClass);
77

88
?>
99
--EXPECTF--
10-
Fatal error: Uncaught Error: Wrong parameters for Error([string $message [, long $code [, Throwable $previous = NULL]]]) in %sexception_022.php:%d
10+
Fatal error: Uncaught TypeError: Error::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
1111
Stack trace:
1212
#0 %sexception_022.php(%d): Error->__construct(Object(stdClass))
1313
#1 {main}

Zend/zend_exceptions.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,11 @@ ZEND_METHOD(exception, __construct)
273273
zend_long code = 0;
274274
zval tmp, *object, *previous = NULL;
275275
zend_class_entry *base_ce;
276-
int argc = ZEND_NUM_ARGS();
277276

278277
object = ZEND_THIS;
279278
base_ce = i_get_exception_base(object);
280279

281-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
282-
zend_class_entry *ce;
283-
284-
if (Z_TYPE(EX(This)) == IS_OBJECT) {
285-
ce = Z_OBJCE(EX(This));
286-
} else if (Z_CE(EX(This))) {
287-
ce = Z_CE(EX(This));
288-
} else {
289-
ce = base_ce;
290-
}
291-
zend_throw_error(NULL, "Wrong parameters for %s([string $message [, long $code [, Throwable $previous = NULL]]])", ZSTR_VAL(ce->name));
280+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
292281
RETURN_THROWS();
293282
}
294283

@@ -344,17 +333,7 @@ ZEND_METHOD(error_exception, __construct)
344333
zval tmp, *object, *previous = NULL;
345334
int argc = ZEND_NUM_ARGS();
346335

347-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|SllSlO!", &message, &code, &severity, &filename, &lineno, &previous, zend_ce_throwable) == FAILURE) {
348-
zend_class_entry *ce;
349-
350-
if (Z_TYPE(EX(This)) == IS_OBJECT) {
351-
ce = Z_OBJCE(EX(This));
352-
} else if (Z_CE(EX(This))) {
353-
ce = Z_CE(EX(This));
354-
} else {
355-
ce = zend_ce_error_exception;
356-
}
357-
zend_throw_error(NULL, "Wrong parameters for %s([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Throwable $previous = NULL]]]]]])", ZSTR_VAL(ce->name));
336+
if (zend_parse_parameters(argc, "|SllSlO!", &message, &code, &severity, &filename, &lineno, &previous, zend_ce_throwable) == FAILURE) {
358337
RETURN_THROWS();
359338
}
360339

0 commit comments

Comments
 (0)