3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringSupported { protected $value; public function __construct(string $string) { $this->value = $string; } public function __toString() { return $this->value; } } class Token { public function replace($text) { if (is_object($text)) { throw new \TypeError("Argument $text expected type string, Object passed"); } echo sprintf('you passed %s', $text); } } $token = new Token(); $token->replace('bob'); $token->replace(new StringSupported('bess'));

preferences:
19.71 ms | 402 KiB | 5 Q