3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
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.
Output for 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
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.
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
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.

preferences:
176.6 ms | 402 KiB | 221 Q