3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface OriginalContract { } interface MoreSpecificContract extends OriginalContract { } class Foo { public function baz(OriginalContract $item) {} } class Bar extends Foo { public function baz(MoreSpecificContract $item) {} } /* I actually want Bar to accept only instances of MoreSpecificContract But for polymorphism, since it extends OriginalContract, it should be valid imho The only way I can now do this is class Bar extends Foo { public function baz(OriginalContract $item) { if (($item instanceof MoreSpecificContract) === false) { throw new Exception("Expected something more specific"); } // do some more specific stuff } } */
based on W6YZq
Output for 7.0.0 - 7.2.0
Warning: Declaration of Bar::baz(MoreSpecificContract $item) should be compatible with Foo::baz(OriginalContract $item) in /in/9aXie on line 19
Output for 5.4.2 - 5.6.28
Strict Standards: Declaration of Bar::baz() should be compatible with Foo::baz(OriginalContract $item) in /in/9aXie on line 19
Output for 5.3.18 - 5.3.29
Strict Standards: Declaration of Bar::baz() should be compatible with that of Foo::baz() in /in/9aXie on line 19