3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface SerializableInterface {} interface SomeResizableInterface {} interface IterableInterface {} trait SomeSerializableTrait {function t2() {} } trait SomeOtherSerializableTrait { function t() {} } class SomeContainer implements SerializableInterface, IterableInterface { use SomeSerializableTrait; } class SomeOtherContainer extends SomeContainer implements SomeResizableInterface { use SomeOtherSerializableTrait; } $someContainer = new SomeContainer; $someOtherContainer = new SomeOtherContainer; var_dump($someContainer instanceof SerializableInterface); var_dump($someOtherContainer instanceof SerializableInterface); var_dump($someOtherContainer instanceof SomeSerializableTrait); var_dump($someOtherContainer instanceof SomeOtherSerializableTrait); // type hint it function testTrait(SomeSerializableTrait $container) {} function testOtherTrait(SomeOtherSerializableTrait $container) {} function testInterface(SomeResizableInterface $container) {} testInterface($someOtherContainer); testOtherTrait($someOtherContainer); testTrait($someOtherContainer);
based on 0SOSA
Output for 7.0.0 - 7.2.0
bool(true) bool(true) bool(false) bool(false) Fatal error: Uncaught TypeError: Argument 1 passed to testOtherTrait() must be an instance of SomeOtherSerializableTrait, instance of SomeOtherContainer given, called in /in/BIGr5 on line 32 and defined in /in/BIGr5:28 Stack trace: #0 /in/BIGr5(32): testOtherTrait(Object(SomeOtherContainer)) #1 {main} thrown in /in/BIGr5 on line 28
Process exited with code 255.
Output for 5.4.1 - 5.6.28
bool(true) bool(true) bool(false) bool(false) Catchable fatal error: Argument 1 passed to testOtherTrait() must be an instance of SomeOtherSerializableTrait, instance of SomeOtherContainer given, called in /in/BIGr5 on line 32 and defined in /in/BIGr5 on line 28
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/BIGr5 on line 6
Process exited with code 255.