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 = null; public Node $leftChild = null; public function eval() : int { if (null != $this->rightChild) { 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 7.4.0 - 7.4.26, 8.0.0 - 8.0.13
Fatal error: Default value for property of type Node may not be null. Use the nullable type ?Node to allow null default value in /in/njve5 on line 12
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/njve5 on line 10
Process exited with code 255.

preferences:
197.72 ms | 1395 KiB | 67 Q