3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
bool(true) bool(true) bool(false) bool(false) Fatal error: Uncaught TypeError: testOtherTrait(): Argument #1 ($container) must be of type SomeOtherSerializableTrait, 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 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
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.4.45, 5.5.24 - 5.5.35, 5.6.8 - 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.

preferences:
192.68 ms | 402 KiB | 226 Q