3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Foo {} interface Bar { /** * @return scalar|array|object|null */ public function __get(string $k); } function Baz(string $thing) : bool { return method_exists($thing, '__get'); } function Bat(string $thing) : bool { return (class_exists($thing) || interface_exists($thing)) && (new ReflectionClass($thing))->hasMethod('__get'); } var_dump(Baz(Foo::class), Bat(Foo::class), Baz(Bar::class), Bat(Bar::class));
Output for 7.1.0 - 7.1.33, 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.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
bool(false) bool(false) bool(true) bool(true)

preferences:
42.57 ms | 407 KiB | 5 Q