3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface SerializableInterface {}; interface SomeResizableInterface {}; interface IterableInterface {}; trait SomeSerializableTrait {}; trait SomeOtherSerializableTrait {}; 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); // type hint it function testTrait(SomeSerializableTrait $container) {} function testInterface(SomeResizableInterface $container) {} testTrait($someOtherContainer); testInterface($someOtherContainer);
based on Q2Y6j
Output for 7.0.0 - 7.2.0
bool(true) bool(true) bool(false) Fatal error: Uncaught TypeError: Argument 1 passed to testTrait() must be an instance of SomeSerializableTrait, instance of SomeOtherContainer given, called in /in/4dN3n on line 29 and defined in /in/4dN3n:26 Stack trace: #0 /in/4dN3n(29): testTrait(Object(SomeOtherContainer)) #1 {main} thrown in /in/4dN3n on line 26
Process exited with code 255.
Output for 5.4.8 - 5.6.28
bool(true) bool(true) bool(false) Catchable fatal error: Argument 1 passed to testTrait() must be an instance of SomeSerializableTrait, instance of SomeOtherContainer given, called in /in/4dN3n on line 29 and defined in /in/4dN3n on line 26
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/4dN3n on line 6
Process exited with code 255.