3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php interface NodeInterface { public function addNode(NodeInterface $node); public function hasNodes(); public function getKey(); public function setKey($key); public function getNodes(); public function nodes(); public function getUid(); public function uid(); public function key(); } interface LeafInterface extends NodeInterface { public function getValue(); public function value(); } abstract class AbstractNode implements NodeInterface { protected $uid; protected $nodes; protected $key; public function __construct($key) { $this->uid = rand(0, 9) . md5(rand(10, 99) . time() . rand(100, 999)) . rand(1000, 9999); $this->key = $key; $this->nodes = []; } public function getKey() { return $this->value->key; } public function key() { return $this->value->key; } public function setKey($key) { $this->value->key = $key; return $this; } public function getUid() { return $this->uid; } public function uid() { return $this->uid; } } class ArrNode extends AbstractNode { public function addNode(NodeInterface $node) { $this->nodes[] = $node; return $this; } public function hasNodes() { return count($this->nodes) > 0; } public function getNodes() { return $this->nodes; } public function nodes() { return $this->nodes; } } class ArrLeaf extends AbstractNode implements LeafInterface { protected $value; public function __construct($key, $value) { parent::__construct($key); $this->value = $value; } public function addNode(NodeInterface $node) { return false; } public function hasNodes() { return false; } public function getNodes() { return false; } public function nodes() { return false; } public function getValue() { return $this->value; } public function value() { return $this->value; } } $pk = new ArrNode('pk'); $pkAttrs = new ArrNode('@attributes'); $pkAttrs->addNode(new ArrLeaf('excl', 'web_actions')); $pkAttrs->addNode(new ArrLeaf('system', 'depWEBsys')); $pkAttrs->addNode(new ArrLeaf('id', 'packet20130905133323986')); $comp->addNode($pkAttrs); var_dump($comp);
Output for 7.0.5 - 7.1.0
Notice: Undefined variable: comp in /in/f4uOV on line 134 Fatal error: Uncaught Error: Call to a member function addNode() on null in /in/f4uOV:134 Stack trace: #0 {main} thrown in /in/f4uOV on line 134
Process exited with code 255.
Output for 7.0.0 - 7.0.4
Notice: Undefined variable: comp in /in/f4uOV on line 134 Fatal error: Uncaught Error: Call to a member function addNode() on unknown in /in/f4uOV:134 Stack trace: #0 {main} thrown in /in/f4uOV on line 134
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined variable: comp in /in/f4uOV on line 134 Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function addNode() on a non-object (null)' in /in/f4uOV:134 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Notice: Undefined variable: comp in /in/f4uOV on line 134 Fatal error: Call to a member function addNode() on null in /in/f4uOV on line 134
Process exited with code 255.
Output for 5.4.0 - 5.5.37
Notice: Undefined variable: comp in /in/f4uOV on line 134 Fatal error: Call to a member function addNode() on a non-object in /in/f4uOV on line 134
Process exited with code 255.
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/f4uOV on line 32
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/f4uOV on line 32
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING in /in/f4uOV on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING in /in/f4uOV on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/f4uOV on line 3
Process exited with code 255.