3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface NodeInterface { public function addNode(Node $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 vlaue(); } 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(Node $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(Node $node) { return false; } public function hasNodes() { return false; } public function getNodes() { return false; } public function nodes() { return false; } } $pk = new ArrComp('pk'); $pkAttrs = new ArrComp('@attributes'); $pkAttrs->addNode(new ArraLeaf('excl', 'web_actions')); $pkAttrs->addNode(new ArraLeaf('system', 'depWEBsys')); $pkAttrs->addNode(new ArraLeaf('id', 'packet20130905133323986')); $comp->addNode($pkAttrs); var_dump($comp);

preferences:
32.42 ms | 402 KiB | 5 Q