3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private function foo(int $bar) { echo "This is private"; } public function getClosure($bar) { return function () use ($bar) { $this->foo($bar); }; } } class B extends A { public function test(A $a, C $c) { $aFN = $a->getClosure("Hello"); $bFN = $this->getClosure("Hello"); $cFN = $c->getClosure("Hello"); $aFN(); $cFN(); } } class C extends B { public function foo(bool $bar) { echo "This is public"; } public function getClosure($bar) { return function () use ($bar) { $this->foo($bar); }; } } $a = new A; $c = new B; $obj = new B(); $obj->test($a, $c);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: B::test(): Argument #2 ($c) must be of type C, B given, called in /in/PNhTl on line 36 and defined in /in/PNhTl:14 Stack trace: #0 /in/PNhTl(36): B->test(Object(A), Object(B)) #1 {main} thrown in /in/PNhTl on line 14
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
57.67 ms | 401 KiB | 8 Q