3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class CanBeStrung { public function __toString(): string { return 'I\'m highly strung'; } } function isItStringy(string|Stringable $possibleStringType): bool { return true; } assert(isItStringy('a string') === true); assert(isItStringy(new CanBeStrung()) === true); try { assert(isItStringy(42) === false); } catch (TypeError $e) { echo '42 isnt a string' . PHP_EOL; } try { assert(isItStringy(new stdClass()) === false); } catch (TypeError $e) { echo 'stdClass cant be strung' . PHP_EOL; }

preferences:
32.52 ms | 404 KiB | 5 Q