3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A {} class B extends A {} class Foo { public function test(B $a) { var_dump(get_class($a)); } } class Bar extends Foo { public function test(A $a) { parent::test($a); } } (new Foo)->test(new A); (new Foo)->test(new B); (new Bar)->test(new A); (new Bar)->test(new B);
based on RAYTX
Output for 7.0.0 - 7.2.6
Warning: Declaration of Bar::test(A $a) should be compatible with Foo::test(B $a) in /in/dHDQt on line 14 Fatal error: Uncaught TypeError: Argument 1 passed to Foo::test() must be an instance of B, instance of A given, called in /in/dHDQt on line 16 and defined in /in/dHDQt:6 Stack trace: #0 /in/dHDQt(16): Foo->test(Object(A)) #1 {main} thrown in /in/dHDQt on line 6
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught TypeError: Argument 1 passed to Foo::test() must be an instance of B, A given in /in/dHDQt:8 Stack trace: #0 /in/dHDQt(16): Foo->test() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Strict Standards: Declaration of Bar::test() should be compatible with Foo::test(B $a) in /in/dHDQt on line 14 Catchable fatal error: Argument 1 passed to Foo::test() must be an instance of B, instance of A given, called in /in/dHDQt on line 16 and defined in /in/dHDQt on line 6
Process exited with code 255.