3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bar { private $candy = 'sweet'; } class Baz { public function __invoke(Bar $bar) { return $bar->candy; } } $bar = new Bar; $baz = new Baz; var_dump(Closure::bind($baz, null, Bar::class)->__invoke($bar));
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught TypeError: Closure::bind(): Argument #1 ($closure) must be of type Closure, Baz given in /in/YLvfZ:9 Stack trace: #0 /in/YLvfZ(9): Closure::bind(Object(Baz), NULL, 'Bar') #1 {main} thrown in /in/YLvfZ on line 9
Process exited with code 255.
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Warning: Closure::bind() expects parameter 1 to be Closure, object given in /in/YLvfZ on line 9 Fatal error: Uncaught Error: Call to a member function __invoke() on null in /in/YLvfZ:9 Stack trace: #0 {main} thrown in /in/YLvfZ on line 9
Process exited with code 255.

preferences:
107.8 ms | 1455 KiB | 4 Q