Skip to content

Commit aff4ce2

Browse files
committed
Improve type error messages when an object is given
Additionally, make the format of return type errors match the format of argument errors.
1 parent f825c0b commit aff4ce2

40 files changed

+158
-161
lines changed

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/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}

Zend/tests/return_types/001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function test1() : array {
77

88
test1();
99
--EXPECTF--
10-
Fatal error: Uncaught TypeError: Return value of test1() must be of type array, none returned in %s:%d
10+
Fatal error: Uncaught TypeError: test1(): Return value must be of type array, none returned in %s:%d
1111
Stack trace:
1212
#0 %s(%d): test1()
1313
#1 {main}

Zend/tests/return_types/002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function test1() : array {
88

99
test1();
1010
--EXPECTF--
11-
Fatal error: Uncaught TypeError: Return value of test1() must be of type array, null returned in %s:%d
11+
Fatal error: Uncaught TypeError: test1(): Return value must be of type array, null returned in %s:%d
1212
Stack trace:
1313
#0 %s(%d): test1()
1414
#1 {main}

Zend/tests/return_types/003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function test1() : array {
77
}
88
test1();
99
--EXPECTF--
10-
Fatal error: Uncaught TypeError: Return value of test1() must be of type array, int returned in %s:%d
10+
Fatal error: Uncaught TypeError: test1(): Return value must be of type array, int returned in %s:%d
1111
Stack trace:
1212
#0 %s(%d): test1()
1313
#1 {main}

Zend/tests/return_types/004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function test1() : array {
88

99
test1();
1010
--EXPECTF--
11-
Fatal error: Uncaught TypeError: Return value of test1() must be of type array, string returned in %s:%d
11+
Fatal error: Uncaught TypeError: test1(): Return value must be of type array, string returned in %s:%d
1212
Stack trace:
1313
#0 %s(%d): test1()
1414
#1 {main}

0 commit comments

Comments
 (0)