3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Stack { public $maxSize; public $items = []; public $top = 0; public function __construct(array $stack, $maxSize){ $this->items = $stack; $this->maxSize = $maxSize; } public function push($item){ if ($this->top === $this->maxSize){ throw new Exception("Stack overflow"); } $this->items[$this->top] = $item; $this->top++; } public function pop(){ if ($this->top === 0){ throw new Exception("Stack underflow"); } $this->top--; return $this->items[$this->top]; } } $items = [1, 2, 3, 4, 5]; $maxSize = 10; $stack = new Stack($items, $maxSize); $stack->push(6); var_dump($stack); $stack->pop(); var_dump($stack);
Output for git.master, git.master_jit, rfc.property-hooks
object(Stack)#1 (3) { ["maxSize"]=> int(10) ["items"]=> array(5) { [0]=> int(6) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) } ["top"]=> int(1) } object(Stack)#1 (3) { ["maxSize"]=> int(10) ["items"]=> array(5) { [0]=> int(6) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) } ["top"]=> int(0) }

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:
160.83 ms | 406 KiB | 5 Q