3v4l.org

run code in 300+ PHP versions simultaneously
<?php class integer { private $value; public function __construct(int ...$value) { switch (count($value)) { case 0: break; case 1: $this->value = $value[0]; break; default: throw new Exception('Multiple values given.'); } } public function __invoke(int ...$value) : int { switch (count($value)) { case 0: break; case 1: $this->value = $value[0]; break; default: throw new Exception('Multiple values given.'); } return $this->value; } public function __toString() : int { return $this->value; } } $testi = new integer(); $testi(2); echo $testi;
Output for 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: integer::__toString(): Return type must be string when declared in /in/t61pJ on line 33
Process exited with code 255.
Output for 8.0.0 - 8.0.13
Fatal error: Declaration of integer::__toString(): int must be compatible with Stringable::__toString(): string in /in/t61pJ on line 33
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Method integer::__toString() must return a string value in /in/t61pJ:40 Stack trace: #0 {main} thrown in /in/t61pJ on line 40
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Recoverable fatal error: Method integer::__toString() must return a string value in /in/t61pJ on line 40
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Catchable fatal error: Method integer::__toString() must return a string value in /in/t61pJ on line 40
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/t61pJ on line 19
Process exited with code 255.
Output for 5.5.24 - 5.5.35
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/t61pJ on line 6
Process exited with code 255.

preferences:
178.3 ms | 401 KiB | 213 Q