3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class StringCastable { private $data; public function __constructor(string $data) { $this->data = $data; } public function __toString(): string { return $this->toString(); } public function toString(): string { return $this->data; } } function testStringCast(string $data) { var_dump($data, get_class($data)); } $speculoos = new StringCastable("speculoos"); var_dump($speculoos, (string)$speculoos); testStringCast($speculoos);
based on Nd5AX
Output for 7.0.1 - 7.2.0
Fatal error: Method StringCastable::__toString() must not throw an exception, caught TypeError: Return value of StringCastable::toString() must be of the type string, null returned in /in/kWZOf on line 0
Process exited with code 255.
Output for 7.0.0
Fatal error: Method StringCastable::__toString() must not throw an exception in /in/kWZOf on line 0
Process exited with code 255.
Output for 5.3.18 - 5.6.28
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/kWZOf on line 12
Process exited with code 255.