push(new Register()); } /** * Peek current Register. Does not change stack. */ public function current(): Register { return array_last($this->registerStack); } /** * Add a new Register instance to top of stack */ public function push(Register $register): void { $this->registerStack[] = $register; } /** * Remove top of stack Register and return it. * Re-inits with an empty register if empty to avoid exception or nullable handling * in consumers if there is for example a "RESTORE_REGISTER" cObj too much. As * drawback, consumers never know if there is a leftover pop(). */ public function pop(): Register { $register = array_pop($this->registerStack); if (empty($this->registerStack)) { $this->push(new Register()); } return $register; } }