3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ExpressionCalculator { public function calc($expression) { $operands = array(); while (($token = strtok($expression, ' ')) !== false) { if (isOperator($token)) { $rightOperand = array_pop($operands); $leftOperand = array_pop($operands); $result = $this->execute($token, $leftOperand, $rightOperand); array_push($operands, $result); continue; } array_push($operands, $token); } return $result; } } $calc = new ExpressionCalculator(); echo $calc->calc('5 1 2 + 4 * + 3 -'); // 14
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZE8NM
function name:  (null)
number of ops:  8
compiled vars:  !0 = $calc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   NEW                                              $1      'ExpressionCalculator'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   26     3        INIT_METHOD_CALL                                         !0, 'calc'
          4        SEND_VAL_EX                                              '5+1+2+%2B+4+%2A+%2B+3+-'
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
          7      > RETURN                                                   1

Class ExpressionCalculator:
Function calc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 3
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 26
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 3
Branch analysis from position: 37
Branch analysis from position: 3
filename:       /in/ZE8NM
function name:  calc
number of ops:  39
compiled vars:  !0 = $expression, !1 = $operands, !2 = $token, !3 = $rightOperand, !4 = $leftOperand, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        ASSIGN                                                   !1, <array>
    8     2      > JMP                                                      ->30
    9     3    >   INIT_FCALL_BY_NAME                                       'isOperator'
          4        SEND_VAR_EX                                              !2
          5        DO_FCALL                                      0  $7      
          6      > JMPZ                                                     $7, ->26
   10     7    >   INIT_FCALL                                               'array_pop'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !3, $8
   11    11        INIT_FCALL                                               'array_pop'
         12        SEND_REF                                                 !1
         13        DO_ICALL                                         $10     
         14        ASSIGN                                                   !4, $10
   12    15        INIT_METHOD_CALL                                         'execute'
         16        SEND_VAR_EX                                              !2
         17        SEND_VAR_EX                                              !4
         18        SEND_VAR_EX                                              !3
         19        DO_FCALL                                      0  $12     
         20        ASSIGN                                                   !5, $12
   13    21        INIT_FCALL                                               'array_push'
         22        SEND_REF                                                 !1
         23        SEND_VAR                                                 !5
         24        DO_ICALL                                                 
   15    25      > JMP                                                      ->30
   18    26    >   INIT_FCALL                                               'array_push'
         27        SEND_REF                                                 !1
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                                 
    8    30    >   INIT_FCALL                                               'strtok'
         31        SEND_VAR                                                 !0
         32        SEND_VAL                                                 '+'
         33        DO_ICALL                                         $16     
         34        ASSIGN                                           ~17     !2, $16
         35        TYPE_CHECK                                  1018          ~17
         36      > JMPNZ                                                    ~18, ->3
   21    37    > > RETURN                                                   !5
   22    38*     > RETURN                                                   null

End of function calc

End of class ExpressionCalculator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.21 ms | 1400 KiB | 19 Q