3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface SerializableInterface {}; interface SomeResizableInterface {}; interface IterableInterface {}; trait SomeSerializableTrait {}; class SomeContainer implements SerializableInterface, IterableInterface { use SomeSerializableTrait; } class SomeOtherContainer extends SomeContainer implements SomeResizableInterface {} $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);
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) Fatal error: Uncaught TypeError: testTrait(): Argument #1 ($container) must be of type SomeSerializableTrait, SomeOtherContainer given, called in /in/Q2Y6j on line 26 and defined in /in/Q2Y6j:23 Stack trace: #0 /in/Q2Y6j(26): testTrait(Object(SomeOtherContainer)) #1 {main} thrown in /in/Q2Y6j on line 23
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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/Q2Y6j on line 26 and defined in /in/Q2Y6j:23 Stack trace: #0 /in/Q2Y6j(26): testTrait(Object(SomeOtherContainer)) #1 {main} thrown in /in/Q2Y6j on line 23
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) Catchable fatal error: Argument 1 passed to testTrait() must be an instance of SomeSerializableTrait, instance of SomeOtherContainer given, called in /in/Q2Y6j on line 26 and defined in /in/Q2Y6j on line 23
Process exited with code 255.

preferences:
209.18 ms | 402 KiB | 240 Q