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);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1YfKU
function name:  (null)
number of ops:  19
compiled vars:  !0 = $items, !1 = $maxSize, !2 = $stack
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, <array>
   32     1        ASSIGN                                                   !1, 10
   33     2        NEW                                              $5      'Stack'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !2, $5
   34     7        INIT_METHOD_CALL                                         !2, 'push'
          8        SEND_VAL_EX                                              6
          9        DO_FCALL                                      0          
   35    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                                 
   37    13        INIT_METHOD_CALL                                         !2, 'pop'
         14        DO_FCALL                                      0          
   38    15        INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Class Stack:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1YfKU
function name:  __construct
number of ops:  7
compiled vars:  !0 = $stack, !1 = $maxSize
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN_OBJ                                               'items'
          3        OP_DATA                                                  !0
   11     4        ASSIGN_OBJ                                               'maxSize'
          5        OP_DATA                                                  !1
   12     6      > RETURN                                                   null

End of function __construct

Function push:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1YfKU
function name:  push
number of ops:  15
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        FETCH_OBJ_R                                      ~1      'top'
          2        FETCH_OBJ_R                                      ~2      'maxSize'
          3        IS_IDENTICAL                                             ~1, ~2
          4      > JMPZ                                                     ~3, ->9
   16     5    >   NEW                                              $4      'Exception'
          6        SEND_VAL_EX                                              'Stack+overflow'
          7        DO_FCALL                                      0          
          8      > THROW                                         0          $4
   18     9    >   FETCH_OBJ_R                                      ~7      'top'
         10        FETCH_OBJ_W                                      $6      'items'
         11        ASSIGN_DIM                                               $6, ~7
         12        OP_DATA                                                  !0
   19    13        PRE_INC_OBJ                                              'top'
   20    14      > RETURN                                                   null

End of function push

Function pop:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1YfKU
function name:  pop
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   FETCH_OBJ_R                                      ~0      'top'
          1        IS_IDENTICAL                                             ~0, 0
          2      > JMPZ                                                     ~1, ->7
   24     3    >   NEW                                              $2      'Exception'
          4        SEND_VAL_EX                                              'Stack+underflow'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $2
   26     7    >   PRE_DEC_OBJ                                              'top'
   27     8        FETCH_OBJ_R                                      ~6      'top'
          9        FETCH_OBJ_R                                      ~5      'items'
         10        FETCH_DIM_R                                      ~7      ~5, ~6
         11      > RETURN                                                   ~7
   28    12*     > RETURN                                                   null

End of function pop

End of class Stack.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.92 ms | 1007 KiB | 14 Q