<?php
class Foo {
public function foo(Bar $bar) {
$bar->bar([$this, 'bar']);
}
protected function bar() {
print 'Foobar!'.PHP_EOL;
}
}
class Bar {
public function bar(callable $bar) {
$bar();
}
}
$foo = new Foo;
$bar = new Bar;
$foo->foo($bar);
Fatal error: Uncaught TypeError: Bar::bar(): Argument #1 ($bar) must be of type callable, array given, called in /in/hO6E1 on line 4 and defined in /in/hO6E1:13
Stack trace:
#0 /in/hO6E1(4): Bar->bar(Array)
#1 /in/hO6E1(21): Foo->foo(Object(Bar))
#2 {main}
thrown in /in/hO6E1 on line 13
Process exited with code 255.
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Foo has a deprecated constructor in /in/hO6E1 on line 2
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Bar has a deprecated constructor in /in/hO6E1 on line 12
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Foo::foo(), 0 passed in /in/hO6E1 on line 18 and exactly 1 expected in /in/hO6E1:3
Stack trace:
#0 /in/hO6E1(18): Foo->foo()
#1 {main}
thrown in /in/hO6E1 on line 3
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Foo::foo(), 0 passed in /in/hO6E1 on line 18 and exactly 1 expected in /in/hO6E1:3
Stack trace:
#0 /in/hO6E1(18): Foo->foo()
#1 {main}
thrown in /in/hO6E1 on line 3
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Foo has a deprecated constructor in /in/hO6E1 on line 2
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Bar has a deprecated constructor in /in/hO6E1 on line 12
Fatal error: Uncaught TypeError: Argument 1 passed to Foo::foo() must be an instance of Bar, none given, called in /in/hO6E1 on line 18 and defined in /in/hO6E1:3
Stack trace:
#0 /in/hO6E1(18): Foo->foo()
#1 {main}
thrown in /in/hO6E1 on line 3
Process exited with code 255.
Catchable fatal error: Argument 1 passed to Foo::foo() must be an instance of Bar, none given, called in /in/hO6E1 on line 18 and defined in /in/hO6E1 on line 3
Process exited with code 255.