3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myClass { protected $value; function setValue($value) : self { $this->value = $value; } function doubleValue() : self { $this->value*=2; } function getValue() : self { return $this->value; } } $calculator = new myClass(); $returnValue = $calculator->setValue(3) ->doubleValue() ->getValue(); echo $returnValue;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Fatal error: Uncaught TypeError: myClass::setValue(): Return value must be of type myClass, none returned in /in/7ha2r:10 Stack trace: #0 /in/7ha2r(25): myClass->setValue(3) #1 {main} thrown in /in/7ha2r on line 10
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Return value of myClass::setValue() must be an instance of myClass, none returned in /in/7ha2r:10 Stack trace: #0 /in/7ha2r(25): myClass->setValue(3) #1 {main} thrown in /in/7ha2r on line 10
Process exited with code 255.
Output for 5.5.0 - 5.5.37, 5.6.0 - 5.6.23
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/7ha2r on line 7
Process exited with code 255.

preferences:
179.94 ms | 402 KiB | 220 Q