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));

preferences:
23.99 ms | 408 KiB | 5 Q