3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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); $copy = $testi; var_dump($copy); echo $testi;
based on 6BZ2Z
Output for 7.1.0 - 7.2.0
object(integer)#1 (1) { ["value":"integer":private]=> int(2) } Recoverable fatal error: Method integer::__toString() must return a string value in /in/BkcEL on line 42
Process exited with code 255.
Output for 7.0.0 - 7.0.20
object(integer)#1 (1) { ["value":"integer":private]=> int(2) } Catchable fatal error: Method integer::__toString() must return a string value in /in/BkcEL on line 42
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/BkcEL on line 19
Process exited with code 255.
Output for 5.4.9 - 5.5.35
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/BkcEL on line 6
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '.', expecting '&' or T_VARIABLE in /in/BkcEL on line 6
Process exited with code 255.