3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node implements Countable { private $nodes = []; public function __construct(array $nodes = []) { $this->nodes = $nodes; } public function getCount() { return count($this->nodes); } private function getCountRecursive() { $count = 0; foreach ($this->nodes as $node) { $count += ($node->getCountRecursive() + 1); } return $count; } public function count($mode = COUNT_NORMAL){ if ($mode === COUNT_RECURSIVE) { return $this->getCountRecursive(); } return $this->getCount(); } } $node = new Node([ new Node([ new Node([ new Node([ new Node(), new Node(), new Node(), ]), new Node(), new Node(), ]), new Node(), new Node(), ]), new Node(), ]); var_dump(count($node), count($node, COUNT_RECURSIVE));
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Node::count($mode =  COUNT_NORMAL) should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Mc5k3 on line 23 Fatal error: Uncaught Error: Undefined constant " COUNT_NORMAL" in /in/Mc5k3:23 Stack trace: #0 /in/Mc5k3(48): Node->count() #1 {main} thrown in /in/Mc5k3 on line 23
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.83 ms | 401 KiB | 8 Q