3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class StringCastable { private $data; public function __constructor($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)); } testStringCast(new StringCastable("speculoos"));
based on GI3Y7
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/Nd5AX 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/Nd5AX on line 0
Process exited with code 255.
Output for 5.3.18 - 5.6.21
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/Nd5AX on line 12
Process exited with code 255.