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, $speculoos->__toString()); testStringCast($speculoos);
based on kWZOf
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught TypeError: Return value of StringCastable::toString() must be of the type string, null returned in /in/ZRbRd:19 Stack trace: #0 /in/ZRbRd(14): StringCastable->toString() #1 /in/ZRbRd(30): StringCastable->__toString() #2 {main} thrown in /in/ZRbRd on line 19
Process exited with code 255.
Output for 5.3.18 - 5.6.28
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/ZRbRd on line 12
Process exited with code 255.