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); var_dump($someOtherContainer instanceof SomeOtherSerializableTrait); // type hint it function testTrait(SomeSerializableTrait $container) {} function testOtherTrait(SomeOtherSerializableTrait $container) {} function testInterface(SomeResizableInterface $container) {} try {testInterface($someOtherContainer);} catch(Exception $e) {var_dump($e);} try {testOtherTrait($someOtherContainer);} catch(Exception $e) {var_dump($e);} try {testTrait($someOtherContainer);} catch(Exception $e) {var_dump($e);}
based on BIGr5
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/u0Bjs on line 32 and defined in /in/u0Bjs:28 Stack trace: #0 /in/u0Bjs(32): testOtherTrait(Object(SomeOtherContainer)) #1 {main} thrown in /in/u0Bjs on line 28
Process exited with code 255.
Output for 5.4.0 - 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/u0Bjs on line 32 and defined in /in/u0Bjs on line 28
Process exited with code 255.