Skip to content

Use the default type error message for Exception::__construct() #5460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/exception_018.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ throw new Hello(new stdClass);

?>
--EXPECTF--
Fatal error: Uncaught Error: Wrong parameters for Hello([string $message [, long $code [, Throwable $previous = NULL]]]) in %sexception_018.php:%d
Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Stack trace:
#0 %sexception_018.php(%d): Exception->__construct(Object(stdClass))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/exception_019.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ throw new Exception(new stdClass);

?>
--EXPECTF--
Fatal error: Uncaught Error: Wrong parameters for Exception([string $message [, long $code [, Throwable $previous = NULL]]]) in %sexception_019.php:%d
Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Stack trace:
#0 %sexception_019.php(%d): Exception->__construct(Object(stdClass))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/exception_020.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ throw new MyErrorException(new stdClass);

?>
--EXPECTF--
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
Fatal error: Uncaught TypeError: ErrorException::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Stack trace:
#0 %sexception_020.php(%d): ErrorException->__construct(Object(stdClass))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/exception_021.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ throw new Hello(new stdClass);

?>
--EXPECTF--
Fatal error: Uncaught Error: Wrong parameters for Hello([string $message [, long $code [, Throwable $previous = NULL]]]) in %sexception_021.php:%d
Fatal error: Uncaught TypeError: Error::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Stack trace:
#0 %sexception_021.php(%d): Error->__construct(Object(stdClass))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/exception_022.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ throw new Error(new stdClass);

?>
--EXPECTF--
Fatal error: Uncaught Error: Wrong parameters for Error([string $message [, long $code [, Throwable $previous = NULL]]]) in %sexception_022.php:%d
Fatal error: Uncaught TypeError: Error::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Stack trace:
#0 %sexception_022.php(%d): Error->__construct(Object(stdClass))
#1 {main}
Expand Down
25 changes: 2 additions & 23 deletions Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,22 +273,11 @@ ZEND_METHOD(exception, __construct)
zend_long code = 0;
zval tmp, *object, *previous = NULL;
zend_class_entry *base_ce;
int argc = ZEND_NUM_ARGS();

object = ZEND_THIS;
base_ce = i_get_exception_base(object);

if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
zend_class_entry *ce;

if (Z_TYPE(EX(This)) == IS_OBJECT) {
ce = Z_OBJCE(EX(This));
} else if (Z_CE(EX(This))) {
ce = Z_CE(EX(This));
} else {
ce = base_ce;
}
zend_throw_error(NULL, "Wrong parameters for %s([string $message [, long $code [, Throwable $previous = NULL]]])", ZSTR_VAL(ce->name));
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
RETURN_THROWS();
}

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

if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|SllSlO!", &message, &code, &severity, &filename, &lineno, &previous, zend_ce_throwable) == FAILURE) {
zend_class_entry *ce;

if (Z_TYPE(EX(This)) == IS_OBJECT) {
ce = Z_OBJCE(EX(This));
} else if (Z_CE(EX(This))) {
ce = Z_CE(EX(This));
} else {
ce = zend_ce_error_exception;
}
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));
if (zend_parse_parameters(argc, "|SllSlO!", &message, &code, &severity, &filename, &lineno, &previous, zend_ce_throwable) == FAILURE) {
RETURN_THROWS();
}

Expand Down