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; testInterface($someOtherContainer); $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 r3fid
Output for 7.0.0 - 7.2.0
Notice: Undefined variable: someOtherContainer in /in/0SOSA on line 18 Fatal error: Uncaught TypeError: Argument 1 passed to testInterface() must implement interface SomeResizableInterface, null given, called in /in/0SOSA on line 18 and defined in /in/0SOSA:30 Stack trace: #0 /in/0SOSA(18): testInterface(NULL) #1 {main} thrown in /in/0SOSA on line 30
Process exited with code 255.
Output for 5.4.1 - 5.6.28
Notice: Undefined variable: someOtherContainer in /in/0SOSA on line 18 Catchable fatal error: Argument 1 passed to testInterface() must implement interface SomeResizableInterface, null given, called in /in/0SOSA on line 18 and defined in /in/0SOSA on line 30
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/0SOSA on line 6
Process exited with code 255.