3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict=1); class A { private function foo(float $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(42.5); $bFN = $this->getClosure(42.5); $cFN = $c->getClosure(42.5); $aFN(); $bFN(); $cFN(); } } class C extends B { public function foo(int $bar) { echo "This is public"; } public function getClosure($bar) { return function () use ($bar) { $this->foo($bar); }; } } $a = new A; $c = new c; $obj = new B(); $obj->test($a, $c);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Unsupported declare 'strict' in /in/jrCWD on line 3 This is privateThis is private Deprecated: Implicit conversion from float 42.5 to int loses precision in /in/jrCWD on line 28 This is public
Output for 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Warning: Unsupported declare 'strict' in /in/jrCWD on line 3 This is privateThis is privateThis is public
Output for 7.0.0 - 7.0.6
Warning: Unsupported declare 'strict' in /in/jrCWD on line 3 Warning: Declaration of C::foo(int $bar) should be compatible with A::foo(float $bar) in /in/jrCWD on line 34 This is privateThis is privateThis is public
Output for 5.6.28
Warning: Unsupported declare 'strict' in /in/jrCWD on line 3 Catchable fatal error: Argument 1 passed to A::foo() must be an instance of float, double given, called in /in/jrCWD on line 11 and defined in /in/jrCWD on line 6
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.21
Warning: Unsupported declare 'strict' in /in/jrCWD on line 3 Strict Standards: Declaration of C::foo() should be compatible with A::foo(float $bar) in /in/jrCWD on line 34 Catchable fatal error: Argument 1 passed to A::foo() must be an instance of float, double given, called in /in/jrCWD on line 11 and defined in /in/jrCWD on line 6
Process exited with code 255.

preferences:
169.79 ms | 402 KiB | 183 Q