Skip to content

Make type error messages more consistent #5092

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Zend/tests/008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var_dump(constant("test const"));
echo "Done\n";
?>
--EXPECTF--
TypeError: define() expects parameter 1 to be string, array given
TypeError: define() expects argument #1 ($constant_name) to be of type string, array given

Notice: Constant TRUE already defined in %s on line %d
bool(false)
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/009.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ string(3) "foo"

Warning: get_class() called without object from outside a class in %s on line %d
bool(false)
get_class() expects parameter 1 to be object, string given
get_class() expects argument #1 ($object) to be of type object, string given
string(3) "foo"
string(4) "foo2"
get_class() expects parameter 1 to be object, null given
get_class() expects argument #1 ($object) to be of type object, null given
Done
4 changes: 2 additions & 2 deletions Zend/tests/arrow_functions/006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ try {
--EXPECTF--
int(2)
int(10)
Argument 1 passed to {closure}() must be of the type int, string given, called in %s on line %d
{closure}() expects argument #1 ($x) to be of type int, string given, called in %s on line %d
array(3) {
[0]=>
int(20)
Expand All @@ -41,4 +41,4 @@ array(3) {
[2]=>
int(30)
}
Argument 2 passed to {closure}() must be of the type int or null, string given, called in %s on line %d
{closure}() expects argument #2 ($args) to be of type ?int, string given, called in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/bug31720.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ try {
?>
--EXPECTF--
Warning: Undefined variable: nonesuchvar in %s on line %d
array_walk() expects parameter 2 to be a valid callback, first array member is not a valid class name or object
array_walk() expects argument #2 ($funcname) to be a valid callback, first array member is not a valid class name or object
2 changes: 1 addition & 1 deletion Zend/tests/bug39003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test($obj);
echo "Done\n";
?>
--EXPECTF--
Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of OtherClassName, instance of ClassName given, called in %s on line %d and defined in %s:%d
Fatal error: Uncaught TypeError: test() expects argument #1 ($object) to be of type OtherClassName, ClassName given, called in %s on line %d and defined in %s:%d
Stack trace:
#0 %s(%d): test(Object(ClassName))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug42802.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ok
ok
ok

Fatal error: Uncaught TypeError: Argument 1 passed to foo\test5() must be an instance of bar, instance of foo\bar given, called in %sbug42802.php on line %d and defined in %sbug42802.php:%d
Fatal error: Uncaught TypeError: foo\test5() expects argument #1 ($bar) to be of type bar, foo\bar given, called in %s on line %d and defined in %s:%d
Stack trace:
#0 %s(%d): foo\test5(Object(foo\bar))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug43332_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $foo = new foo;
$foo->bar($foo); // Ok!
$foo->bar(new \stdclass); // Error, ok!
--EXPECTF--
Fatal error: Uncaught TypeError: Argument 1 passed to foobar\foo::bar() must be an instance of foobar\foo, instance of stdClass given, called in %sbug43332_1.php on line 10 and defined in %sbug43332_1.php:5
Fatal error: Uncaught TypeError: foobar\foo::bar() expects argument #1 ($a) to be of type foobar\foo, stdClass given, called in %sbug43332_1.php on line 10 and defined in %sbug43332_1.php:5
Stack trace:
#0 %s(%d): foobar\foo->bar(Object(stdClass))
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug45186.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ string(1) "y"
ok
__callstatic:
string(3) "www"
call_user_func() expects parameter 1 to be a valid callback, cannot access self:: when no class scope is active
call_user_func() expects argument #1 ($function) to be a valid callback, cannot access self:: when no class scope is active
4 changes: 2 additions & 2 deletions Zend/tests/bug45186_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ string(1) "y"
__call:
string(1) "y"
ok
call_user_func() expects parameter 1 to be a valid callback, class 'bar' does not have a method 'www'
call_user_func() expects parameter 1 to be a valid callback, cannot access self:: when no class scope is active
call_user_func() expects argument #1 ($function) to be a valid callback, class 'bar' does not have a method 'www'
call_user_func() expects argument #1 ($function) to be a valid callback, cannot access self:: when no class scope is active
8 changes: 4 additions & 4 deletions Zend/tests/bug48770_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class B extends A {
public function func($str) {
call_user_func_array(array($this, 'parent::func2'), array($str));
call_user_func_array(array($this, 'parent::func3'), array($str));

try {
call_user_func_array(array($this, 'parent::func22'), array($str));
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}

try {
call_user_func_array(array($this, 'parent::inexistent'), array($str));
} catch (\TypeError $e) {
Expand Down Expand Up @@ -58,5 +58,5 @@ $c->func('This should work!');
--EXPECT--
string(27) "A::func2: This should work!"
string(27) "A::func3: This should work!"
call_user_func_array() expects parameter 1 to be a valid callback, cannot access private method A::func22()
call_user_func_array() expects parameter 1 to be a valid callback, class 'A' does not have a method 'inexistent'
call_user_func_array() expects argument #1 ($function) to be a valid callback, cannot access private method A::func22()
call_user_func_array() expects argument #1 ($function) to be a valid callback, class 'A' does not have a method 'inexistent'
4 changes: 2 additions & 2 deletions Zend/tests/bug48770_3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class B extends A {
public function func($str) {
call_user_func_array(array($this, 'self::func2'), array($str));
call_user_func_array(array($this, 'self::func3'), array($str));

try {
call_user_func_array(array($this, 'self::inexistent'), array($str));
} catch (\TypeError $e) {
Expand Down Expand Up @@ -52,4 +52,4 @@ $c->func('This should work!');
--EXPECT--
string(27) "B::func2: This should work!"
string(27) "B::func3: This should work!"
call_user_func_array() expects parameter 1 to be a valid callback, class 'B' does not have a method 'inexistent'
call_user_func_array() expects argument #1 ($function) to be a valid callback, class 'B' does not have a method 'inexistent'
2 changes: 1 addition & 1 deletion Zend/tests/bug61273.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ $args = array_fill(0, 64 * 1024 - 64, 0);
call_user_func_array(function(&$a) {}, $args);
echo strval("okey");
--EXPECTF--
Warning: Parameter 1 to {closure}() expected to be a reference, value given in %sbug61273.php on line %d
Warning: {closure}() expects argument #1 ($a) to be passed by reference, value given in %s on line %d
okey
2 changes: 1 addition & 1 deletion Zend/tests/bug68446.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ array(1) {
int(1)
}

Fatal error: Uncaught TypeError: Argument 1 passed to a() must be of the type array, null given, called in %s on line %d and defined in %s:%d
Fatal error: Uncaught TypeError: a() expects argument #1 ($a) to be of type array, null given, called in %s on line %d and defined in %s:%d
Stack trace:
#0 %s(%d): a(NULL)
#1 {main}
Expand Down
6 changes: 3 additions & 3 deletions Zend/tests/bug70895.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ try {
}
?>
--EXPECT--
array_map() expects parameter 1 to be a valid callback, function '%n' not found or invalid function name
array_map() expects parameter 1 to be a valid callback, function '%n %i' not found or invalid function name
array_map() expects parameter 1 to be a valid callback, function '%n %i aoeu %f aoeu %p' not found or invalid function name
array_map() expects argument #1 ($callback) to be a valid callback, function '%n' not found or invalid function name
array_map() expects argument #1 ($callback) to be a valid callback, function '%n %i' not found or invalid function name
array_map() expects argument #1 ($callback) to be a valid callback, function '%n %i aoeu %f aoeu %p' not found or invalid function name
2 changes: 1 addition & 1 deletion Zend/tests/bug70898.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ try {
}
?>
--EXPECT--
array_map() expects parameter 1 to be a valid callback, function '0000000000000000000000000000000000' not found or invalid function name
array_map() expects argument #1 ($callback) to be a valid callback, function '0000000000000000000000000000000000' not found or invalid function name
2 changes: 1 addition & 1 deletion Zend/tests/bug72101.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ $foo->bar($a, $b, $c);
--EXPECTF--
Fatal error: Uncaught Error: Class 'DoesNotExists' not found in %sbug72101.php:61
Stack trace:
#0 %sbug72101.php(8): {closure}(2, 'Parameter 1 to ...', '%s', 8)
#0 %sbug72101.php(8): {closure}(2, 'MethodCallbackB...', '%s', 8)
#1 %sbug72101.php(27): PHPUnit_Framework_MockObject_Stub_ReturnCallback->invoke(Object(PHPUnit_Framework_MockObject_Invocation_Static))
#2 %sbug72101.php(19): PHPUnit_Framework_MockObject_Matcher->invoked(Object(PHPUnit_Framework_MockObject_Invocation_Static))
#3 %sbug72101.php(52): PHPUnit_Framework_MockObject_InvocationMocker->invoke(Object(PHPUnit_Framework_MockObject_Invocation_Static))
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/bug72598.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ new class {
};
?>
--EXPECTF--
Warning: Parameter 1 to ref() expected to be a reference, value given in %sbug72598.php on line 11
Warning: ref() expects argument #1 ($ref) to be passed by reference, value given in %s on line %d
object(class@anonymous)#1 (0) {
}

Warning: Parameter 1 to ref() expected to be a reference, value given in %sbug72598.php on line 11
Warning: ref() expects argument #1 ($ref) to be passed by reference, value given in %s on line %d
object(class@anonymous)#1 (0) {
}
4 changes: 2 additions & 2 deletions Zend/tests/bug72598_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ new class {
};
?>
--EXPECTF--
Warning: Parameter 1 to ref() expected to be a reference, value given in %sbug72598_2.php on line 14
Warning: ref() expects argument #1 ($ref) to be passed by reference, value given in %s on line %d
int(0)

Warning: Parameter 1 to ref() expected to be a reference, value given in %sbug72598_2.php on line 14
Warning: ref() expects argument #1 ($ref) to be passed by reference, value given in %s on line %d
int(0)
2 changes: 1 addition & 1 deletion Zend/tests/bug73954.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ takes_int(log(tan(3.14)));
float(NAN)
bool(true)

Fatal error: Uncaught TypeError: Argument 1 passed to takes_int() must be of the type int, float given, called in %s on line 9 and defined in %s:6
Fatal error: Uncaught TypeError: takes_int() expects argument #1 ($int) to be of type int, float given, called in %s on line %d and defined in %s:%d
Stack trace:
#0 %s(9): takes_int(NAN)
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug74164.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set_error_handler(function ($type, $msg) {
call_user_func(function (array &$ref) {var_dump("xxx");}, 'not_an_array_variable');
?>
--EXPECTF--
Fatal error: Uncaught Exception: Parameter 1 to Foo\{closure}() expected to be a reference, value given in %sbug74164.php:%d
Fatal error: Uncaught Exception: Foo\{closure}() expects argument #1 ($ref) to be passed by reference, value given in %s:%d
Stack trace:
#0 [internal function]: Foo\{closure}(%s)
#1 %sbug74164.php(%d): call_user_func(%s)
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/call_user_func_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ namespace testing {
?>
--EXPECT--
string(6) "foobar"
call_user_func() expects parameter 1 to be a valid callback, cannot access private method testing\foo::priv()
call_user_func() expects parameter 1 to be a valid callback, cannot access protected method testing\foo::prot()
call_user_func() expects argument #1 ($function) to be a valid callback, cannot access private method testing\foo::priv()
call_user_func() expects argument #1 ($function) to be a valid callback, cannot access protected method testing\foo::prot()
8 changes: 4 additions & 4 deletions Zend/tests/call_user_func_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ try {
?>
--EXPECTF--
string(3) "foo"
call_user_func() expects parameter 1 to be a valid callback, class 'foo' not found
call_user_func() expects parameter 1 to be a valid callback, class '' not found
call_user_func() expects argument #1 ($function) to be a valid callback, class 'foo' not found
call_user_func() expects argument #1 ($function) to be a valid callback, class '' not found

Warning: Undefined variable: foo in %s on line %d
call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
call_user_func() expects argument #1 ($function) to be a valid callback, first array member is not a valid class name or object

Warning: Undefined variable: foo in %s on line %d
call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
call_user_func() expects argument #1 ($function) to be a valid callback, first array member is not a valid class name or object
4 changes: 2 additions & 2 deletions Zend/tests/call_user_func_006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var_dump($y);

?>
--EXPECTF--
Warning: Parameter 1 to Foo\bar() expected to be a reference, value given in %s on line %d
Warning: Foo\bar() expects argument #1 ($ref) to be passed by reference, value given in %s on line %d
int(42)

Warning: Parameter 1 to Foo\bar() expected to be a reference, value given in %s on line %d
Warning: Foo\bar() expects argument #1 ($ref) to be passed by reference, value given in %s on line %d
int(42)
2 changes: 1 addition & 1 deletion Zend/tests/call_user_func_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Notice: Undefined offset: 0 in %s on line %d

Warning: Trying to access array offset on value of type null in %s on line %d

Warning: Parameter 1 to foo() expected to be a reference, value given in %s on line %d
Warning: foo() expects argument #1 ($ref) to be passed by reference, value given in %s on line %d
array(0) {
}
16 changes: 8 additions & 8 deletions Zend/tests/call_user_func_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ var_dump($i, $j);

?>
--EXPECTF--
Warning: Parameter 1 to test() expected to be a reference, value given in %s on line %d
Warning: test() expects argument #1 ($ref1) to be passed by reference, value given in %s on line %d

Warning: Parameter 2 to test() expected to be a reference, value given in %s on line %d
Warning: test() expects argument #2 ($ref2) to be passed by reference, value given in %s on line %d
bool(true)
int(0)
int(0)

Warning: Parameter 1 to test() expected to be a reference, value given in %s on line %d
Warning: test() expects argument #1 ($ref1) to be passed by reference, value given in %s on line %d

Warning: Parameter 2 to test() expected to be a reference, value given in %s on line %d
Warning: test() expects argument #2 ($ref2) to be passed by reference, value given in %s on line %d
bool(true)
int(0)
int(0)

Warning: Parameter 1 to test() expected to be a reference, value given in %s on line %d
Warning: test() expects argument #1 ($ref1) to be passed by reference, value given in %s on line %d

Warning: Parameter 2 to test() expected to be a reference, value given in %s on line %d
Warning: test() expects argument #2 ($ref2) to be passed by reference, value given in %s on line %d
bool(true)
int(0)
int(0)

Warning: Parameter 1 to test() expected to be a reference, value given in %s on line %d
Warning: test() expects argument #1 ($ref1) to be passed by reference, value given in %s on line %d

Warning: Parameter 2 to test() expected to be a reference, value given in %s on line %d
Warning: test() expects argument #2 ($ref2) to be passed by reference, value given in %s on line %d
bool(true)
int(0)
int(0)
4 changes: 2 additions & 2 deletions Zend/tests/call_user_func_009.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var_dump(\call_user_func('sort', []));

?>
--EXPECTF--
Warning: Parameter 1 to sort() expected to be a reference, value given in %s on line %d
Warning: sort() expects argument #1 ($arg) to be passed by reference, value given in %s on line %d
bool(true)

Warning: Parameter 1 to sort() expected to be a reference, value given in %s on line %d
Warning: sort() expects argument #1 ($arg) to be passed by reference, value given in %s on line %d
bool(true)
2 changes: 1 addition & 1 deletion Zend/tests/call_user_func_array_invalid_type.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ try {
}
?>
--EXPECT--
call_user_func_array() expects parameter 2 to be array, null given
call_user_func_array() expects argument #2 ($args) to be of type array, null given
4 changes: 2 additions & 2 deletions Zend/tests/closure_027.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Closure 027: Testing Closure type-hint
--FILE--
<?php

function test(closure $a) {
function test(Closure $a) {
var_dump($a());
}

Expand All @@ -30,7 +30,7 @@ NULL
Warning: Undefined variable: y in %s on line %d
Exception: Too few arguments to function {closure}(), 0 passed in %s on line %d and exactly 1 expected

Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of Closure, instance of stdClass given, called in %s on line %d and defined in %s:%d
Fatal error: Uncaught TypeError: test() expects argument #1 ($a) to be of type Closure, stdClass given, called in %s on line %d and defined in %s:%d
Stack trace:
#0 %s(%d): test(Object(stdClass))
#1 {main}
Expand Down
6 changes: 3 additions & 3 deletions Zend/tests/closure_059.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ try {
echo "Exception: " . $e->getMessage() . "\n";
}
--EXPECTF--
Exception: Argument 1 passed to {closure}() must be an instance of A, instance of B %s
Exception: Argument 1 passed to {closure}() must be an instance of A, instance of B %s
Exception: Argument 1 passed to {closure}() must be an instance of A, instance of B %s
Exception: {closure}() expects argument #1 ($a) to be of type A, B given, called in %s on line %d
Exception: {closure}() expects argument #1 ($a) to be of type A, B given
Exception: {closure}() expects argument #1 ($a) to be of type A, B given
2 changes: 1 addition & 1 deletion Zend/tests/errmsg_013.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
errmsg: default value for parameters with array type can only be an array or NULL
errmsg: default value for parameters with array type can only be an array or null
--FILE--
<?php

Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/exception_017.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Error: Cannot call abstract method C::foo() in %s:%d
Stack trace:
#0 {main}

TypeError: Argument 1 passed to foo() must be callable, string given, called in %s on line %d and defined in %s:%d
TypeError: foo() expects argument #1 ($x) to be of type callable, string given, called in %s on line %d and defined in %s:%d
Stack trace:
#0 %s(%d): foo('C::foo')
#1 {main}
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/exception_handler_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set_exception_handler(array("", ""));
echo "Done\n";
?>
--EXPECTF--
Warning: set_exception_handler() expects the argument (fo) to be a valid callback in %s on line %d
Warning: set_exception_handler() expects argument #1 ($exception_handler) to be a valid callback in %s on line %d

Warning: set_exception_handler() expects the argument (::) to be a valid callback in %s on line %d
Warning: set_exception_handler() expects argument #1 ($exception_handler) to be a valid callback in %s on line %d
Done
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ Too few arguments to function bar(), 1 passed in %s and exactly 2 expected
ArgumentCountError
Too few arguments to function bat(), 1 passed in %s and exactly 2 expected
TypeError
Argument 1 passed to bat() must be of the type int, string given, called in %s
bat() expects argument #1 ($foo) to be of type int, string given, called in %s on line %d
TypeError
Argument 2 passed to bat() must be of the type string, int given, called in %s
bat() expects argument #2 ($bar) to be of type string, int given, called in %s on line %d
22 changes: 22 additions & 0 deletions Zend/tests/function_arguments/variadic_argument_type_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Call userland function with incorrect variadic argument type
--FILE--
<?php

function foo($foo, int ...$bar) {}

try {
foo(1, []);
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}

try {
foo(1, 1, 1, []);
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}

--EXPECTF--
foo() expects argument #2 ($bar) to be of type int, array given, called in %s on line %d
foo() expects argument #4 ($bar) to be of type int, array given, called in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/generators/generator_with_type_check.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function gen(array $a) { yield; }
gen(42);
?>
--EXPECTF--
Fatal error: Uncaught TypeError: Argument 1 passed to gen() must be of the type array, int given, called in %sgenerator_with_type_check.php on line 3 and defined in %sgenerator_with_type_check.php:2
Fatal error: Uncaught TypeError: gen() expects argument #1 ($a) to be of type array, int given, called in %s on line %d and defined in %s:%d
Stack trace:
#0 %sgenerator_with_type_check.php(3): gen(42)
#1 {main}
Expand Down
Loading