3v4l.org

run code in 500+ PHP versions simultaneously
<?php interface One { function callme(string $data): void; } interface Two { function callme(int $data): void; } class OneImpl implements One { function callme(string $data): void {} } class TwoImpl implements Two { function callme(int $data): void {} } class BothImpl implements One, Two { /** * @param int|string $data */ function callme($data): void {} } /** * @param "one"|"two"|"both" $switch * @return One|Two */ function getEither(string $switch) { if ($switch === "one") { return new OneImpl(); } if ($switch === "two") { return new TwoImpl(); } return new BothImpl(); } /** * @param One|Two $impl */ function process($impl): void { if ($impl instanceof One && $impl instanceof Two) { echo 'both'; } elseif ($impl instanceof One) { echo 'one'; } elseif ($impl instanceof Two) { echo 'two'; } } process(getEither("one")); process(getEither("two")); process(getEither("both"));
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.31, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
onetwoboth
Output for 7.1.25 - 7.1.32
Fatal error: Declaration of BothImpl::callme($data): void must be compatible with One::callme(string $data): void in /in/e4tsG on line 19
Process exited with code 255.

preferences:
104.39 ms | 1485 KiB | 4 Q