Skip to content

Commit fbe3059

Browse files
committed
Improve type error messages when an object is given
From now on, we always display the given object's type instead of just reporting "object". Additionally, make the format of return type errors match the format of argument errors. Closes GH-5625
1 parent 38c85ef commit fbe3059

File tree

134 files changed

+751
-750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+751
-750
lines changed

Zend/tests/add_002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ var_dump($c);
2020
echo "Done\n";
2121
?>
2222
--EXPECTF--
23-
Exception: Unsupported operand types: array + object
23+
Exception: Unsupported operand types: array + stdClass
2424

25-
Fatal error: Uncaught TypeError: Unsupported operand types: array + object in %s:%d
25+
Fatal error: Uncaught TypeError: Unsupported operand types: array + stdClass in %s:%d
2626
Stack trace:
2727
#0 {main}
2828
thrown in %s on line %d

Zend/tests/add_003.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ var_dump($c);
2020
echo "Done\n";
2121
?>
2222
--EXPECTF--
23-
Exception: Unsupported operand types: object + array
23+
Exception: Unsupported operand types: stdClass + array
2424

25-
Fatal error: Uncaught TypeError: Unsupported operand types: object + array in %s:%d
25+
Fatal error: Uncaught TypeError: Unsupported operand types: stdClass + array in %s:%d
2626
Stack trace:
2727
#0 {main}
2828
thrown in %s on line %d

Zend/tests/bug26166.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ try {
6464
--EXPECT--
6565
Hello World!
6666
===NONE===
67-
Return value of NoneTest::__toString() must be of type string, none returned
67+
NoneTest::__toString(): Return value must be of type string, none returned
6868
===THROW===
6969
This is an error!

Zend/tests/bug54305.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ try {
1616
}
1717
?>
1818
--EXPECT--
19-
Cannot increment object
19+
Cannot increment ReflectionMethod

Zend/tests/decrement_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ float(1.5)
5656
NULL
5757
bool(true)
5858
bool(false)
59-
Cannot decrement object
59+
Cannot decrement stdClass
6060
object(stdClass)#%d (0) {
6161
}
6262
Cannot decrement array

Zend/tests/decrement_001_64bit.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ float(1.5)
5656
NULL
5757
bool(true)
5858
bool(false)
59-
Cannot decrement object
59+
Cannot decrement stdClass
6060
object(stdClass)#1 (0) {
6161
}
6262
Cannot decrement array

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 TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
11+
Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, stdClass 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 TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
10+
Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, stdClass 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 TypeError: ErrorException::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
11+
Fatal error: Uncaught TypeError: ErrorException::__construct(): Argument #1 ($message) must be of type string, stdClass 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 TypeError: Error::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
11+
Fatal error: Uncaught TypeError: Error::__construct(): Argument #1 ($message) must be of type string, stdClass 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 TypeError: Error::__construct(): Argument #1 ($message) must be of type string, object given in %s:%d
10+
Fatal error: Uncaught TypeError: Error::__construct(): Argument #1 ($message) must be of type string, stdClass given in %s:%d
1111
Stack trace:
1212
#0 %sexception_022.php(%d): Error->__construct(Object(stdClass))
1313
#1 {main}

Zend/tests/generators/throw_not_an_exception.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $gen->throw(new stdClass);
1212

1313
?>
1414
--EXPECTF--
15-
Fatal error: Uncaught TypeError: Generator::throw(): Argument #1 ($exception) must be of type Throwable, object given in %s:%d
15+
Fatal error: Uncaught TypeError: Generator::throw(): Argument #1 ($exception) must be of type Throwable, stdClass given in %s:%d
1616
Stack trace:
1717
#0 %s(%d): Generator->throw(Object(stdClass))
1818
#1 {main}

Zend/tests/increment_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ float(3.5)
5656
int(1)
5757
bool(true)
5858
bool(false)
59-
Cannot increment object
59+
Cannot increment stdClass
6060
object(stdClass)#%d (0) {
6161
}
6262
Cannot increment array

Zend/tests/ns_071.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ new bar(new \stdclass);
1818
--EXPECTF--
1919
NULL
2020

21-
Fatal error: Uncaught TypeError: foo\bar::__construct(): Argument #1 ($x) must be of type ?array, object given, called in %s:%d
21+
Fatal error: Uncaught TypeError: foo\bar::__construct(): Argument #1 ($x) must be of type ?array, stdClass given, called in %s:%d
2222
Stack trace:
2323
#0 %s(%d): foo\bar->__construct(Object(stdClass))
2424
#1 {main}

Zend/tests/object_types/return_type_in_class.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $three = new class extends Two {
1818
};
1919
$three->a();
2020
--EXPECTF--
21-
Fatal error: Uncaught TypeError: Return value of Two@anonymous::a() must be of type object, int returned in %s:%d
21+
Fatal error: Uncaught TypeError: Two@anonymous::a(): Return value must be of type object, int returned in %s:%d
2222
Stack trace:
2323
#0 %s(%d): Two@anonymous->a()
2424
#1 {main}

Zend/tests/object_types/return_type_in_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function a() : object {
88
}
99
a();
1010
--EXPECTF--
11-
Fatal error: Uncaught TypeError: Return value of a() must be of type object, int returned in %s:4
11+
Fatal error: Uncaught TypeError: a(): Return value must be of type object, int returned in %s:%d
1212
Stack trace:
1313
#0 %s(6): a()
1414
#1 {main}

Zend/tests/object_types/return_type_inheritance_in_class.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $three = new class extends Two {
1818
};
1919
$three->a();
2020
--EXPECTF--
21-
Fatal error: Uncaught TypeError: Return value of Two@anonymous::a() must be of type object, int returned in %s:%d
21+
Fatal error: Uncaught TypeError: Two@anonymous::a(): Return value must be of type object, int returned in %s:%d
2222
Stack trace:
2323
#0 %s(%d): Two@anonymous->a()
2424
#1 {main}

Zend/tests/object_types/return_type_inheritance_in_interface.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $three = new class implements Two {
1818
};
1919
$three->a();
2020
--EXPECTF--
21-
Fatal error: Uncaught TypeError: Return value of Two@anonymous::a() must be of type object, int returned in %s:%d
21+
Fatal error: Uncaught TypeError: Two@anonymous::a(): Return value must be of type object, int returned in %s:%d
2222
Stack trace:
2323
#0 %s(%d): Two@anonymous->a()
2424
#1 {main}

0 commit comments

Comments
 (0)