Skip to content

Improve type error messages when an object is given #5625

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 3 commits 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
4 changes: 2 additions & 2 deletions Zend/tests/add_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var_dump($c);
echo "Done\n";
?>
--EXPECTF--
Exception: Unsupported operand types: array + object
Exception: Unsupported operand types: array + stdClass

Fatal error: Uncaught TypeError: Unsupported operand types: array + object in %s:%d
Fatal error: Uncaught TypeError: Unsupported operand types: array + stdClass in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
4 changes: 2 additions & 2 deletions Zend/tests/add_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var_dump($c);
echo "Done\n";
?>
--EXPECTF--
Exception: Unsupported operand types: object + array
Exception: Unsupported operand types: stdClass + array

Fatal error: Uncaught TypeError: Unsupported operand types: object + array in %s:%d
Fatal error: Uncaught TypeError: Unsupported operand types: stdClass + array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/bug26166.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ try {
--EXPECT--
Hello World!
===NONE===
Return value of NoneTest::__toString() must be of type string, none returned
NoneTest::__toString(): Return value must be of type string, none returned
===THROW===
This is an error!
2 changes: 1 addition & 1 deletion Zend/tests/bug54305.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ try {
}
?>
--EXPECT--
Cannot increment object
Cannot increment ReflectionMethod
2 changes: 1 addition & 1 deletion Zend/tests/decrement_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ float(1.5)
NULL
bool(true)
bool(false)
Cannot decrement object
Cannot decrement stdClass
object(stdClass)#%d (0) {
}
Cannot decrement array
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/decrement_001_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ float(1.5)
NULL
bool(true)
bool(false)
Cannot decrement object
Cannot decrement stdClass
object(stdClass)#1 (0) {
}
Cannot decrement array
Expand Down
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 TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, stdClass 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 TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, stdClass 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 TypeError: ErrorException::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Fatal error: Uncaught TypeError: ErrorException::__construct(): Argument #1 ($message) must be of type string, stdClass 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 TypeError: Error::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Fatal error: Uncaught TypeError: Error::__construct(): Argument #1 ($message) must be of type string, stdClass 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 TypeError: Error::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
Fatal error: Uncaught TypeError: Error::__construct(): Argument #1 ($message) must be of type string, stdClass given in %s:%d
Stack trace:
#0 %sexception_022.php(%d): Error->__construct(Object(stdClass))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/generators/throw_not_an_exception.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $gen->throw(new stdClass);

?>
--EXPECTF--
Fatal error: Uncaught TypeError: Generator::throw(): Argument #1 ($exception) must be of type Throwable, object given in %s:%d
Fatal error: Uncaught TypeError: Generator::throw(): Argument #1 ($exception) must be of type Throwable, stdClass given in %s:%d
Stack trace:
#0 %s(%d): Generator->throw(Object(stdClass))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/increment_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ float(3.5)
int(1)
bool(true)
bool(false)
Cannot increment object
Cannot increment stdClass
object(stdClass)#%d (0) {
}
Cannot increment array
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/ns_071.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ new bar(new \stdclass);
--EXPECTF--
NULL

Fatal error: Uncaught TypeError: foo\bar::__construct(): Argument #1 ($x) must be of type ?array, object given, called in %s:%d
Fatal error: Uncaught TypeError: foo\bar::__construct(): Argument #1 ($x) must be of type ?array, stdClass given, called in %s:%d
Stack trace:
#0 %s(%d): foo\bar->__construct(Object(stdClass))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/object_types/return_type_in_class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $three = new class extends Two {
};
$three->a();
--EXPECTF--
Fatal error: Uncaught TypeError: Return value of Two@anonymous::a() must be of type object, int returned in %s:%d
Fatal error: Uncaught TypeError: Two@anonymous::a(): Return value must be of type object, int returned in %s:%d
Stack trace:
#0 %s(%d): Two@anonymous->a()
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/object_types/return_type_in_function.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function a() : object {
}
a();
--EXPECTF--
Fatal error: Uncaught TypeError: Return value of a() must be of type object, int returned in %s:4
Fatal error: Uncaught TypeError: a(): Return value must be of type object, int returned in %s:%d
Stack trace:
#0 %s(6): a()
#1 {main}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $three = new class extends Two {
};
$three->a();
--EXPECTF--
Fatal error: Uncaught TypeError: Return value of Two@anonymous::a() must be of type object, int returned in %s:%d
Fatal error: Uncaught TypeError: Two@anonymous::a(): Return value must be of type object, int returned in %s:%d
Stack trace:
#0 %s(%d): Two@anonymous->a()
#1 {main}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $three = new class implements Two {
};
$three->a();
--EXPECTF--
Fatal error: Uncaught TypeError: Return value of Two@anonymous::a() must be of type object, int returned in %s:%d
Fatal error: Uncaught TypeError: Two@anonymous::a(): Return value must be of type object, int returned in %s:%d
Stack trace:
#0 %s(%d): Two@anonymous->a()
#1 {main}
Expand Down
Loading