3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface NodeInterface { public function eval() : int; } class Node implements NodeInterface { public int $value; public string $sign; public Node $rightChild; public Node $leftChild; public function eval() : int { if ($rightChild != null) { return $this->value; } switch ($this->sign) { case "+": return $this->leftChild->value + $this->rightChild->value; //... } } } $root = new Node(); $root->value = 10; echo $root->eval();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Warning: Undefined variable $rightChild in /in/aORsu on line 17 Fatal error: Uncaught Error: Typed property Node::$sign must not be accessed before initialization in /in/aORsu:21 Stack trace: #0 /in/aORsu(31): Node->eval() #1 {main} thrown in /in/aORsu on line 21
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Notice: Undefined variable: rightChild in /in/aORsu on line 17 Fatal error: Uncaught Error: Typed property Node::$sign must not be accessed before initialization in /in/aORsu:21 Stack trace: #0 /in/aORsu(31): Node->eval() #1 {main} thrown in /in/aORsu on line 21
Process exited with code 255.
Output for 7.3.13 - 7.3.33
Parse error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/aORsu on line 10
Process exited with code 255.

preferences:
164.51 ms | 401 KiB | 139 Q