3v4l.org

run code in 300+ PHP versions simultaneously
<?php function Parenthesis($string) { $opening = array('}' => '{', ']' => '[', ')' => '('); $parens = array(); foreach (str_split($string) as $char) { switch ($char) { case '{': case '[': case '(': $parens[] = $char; break; case '}': case ']': case ')': if (!count($parens) || array_pop($parens) != $opening[$char]) return false; break; default: break; } } return count($parens) === 0; } function check_balanced($string) { echo "$string is " . (Parenthesis($string) ? '' : 'not ') . "balanced\n"; } check_balanced("{([]){}()}"); check_balanced("{C{}[{[a]}RqhL]{y2}}"); check_balanced("{([]){]()}");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RJftQ
function name:  (null)
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'check_balanced'
          1        SEND_VAL                                                 '%7B%28%5B%5D%29%7B%7D%28%29%7D'
          2        DO_FCALL                                      0          
   30     3        INIT_FCALL                                               'check_balanced'
          4        SEND_VAL                                                 '%7BC%7B%7D%5B%7B%5Ba%5D%7DRqhL%5D%7By2%7D%7D'
          5        DO_FCALL                                      0          
   31     6        INIT_FCALL                                               'check_balanced'
          7        SEND_VAL                                                 '%7B%28%5B%5D%29%7B%5D%28%29%7D'
          8        DO_FCALL                                      0          
          9      > RETURN                                                   1

Function parenthesis:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 40
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 40
Branch analysis from position: 8
8 jumps found. (Code = 188) Position 1 = 22, Position 2 = 22, Position 3 = 22, Position 4 = 25, Position 5 = 25, Position 6 = 25, Position 7 = 38, Position 8 = 9
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 22
Branch analysis from position: 22
Branch analysis from position: 25
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 34
Branch analysis from position: 25
Branch analysis from position: 25
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 25
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 25
Branch analysis from position: 25
Branch analysis from position: 25
Branch analysis from position: 22
Branch analysis from position: 22
Branch analysis from position: 22
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/RJftQ
function name:  Parenthesis
number of ops:  45
compiled vars:  !0 = $string, !1 = $opening, !2 = $parens, !3 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    6     3        INIT_FCALL                                               'str_split'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $6      
          6      > FE_RESET_R                                       $7      $6, ->40
          7    > > FE_FETCH_R                                               $7, !3, ->40
    7     8    > > SWITCH_STRING                                            !3, [ '%7B':->22, '%5B':->22, '%28':->22, '%7D':->25, '%5D':->25, '%29':->25, ], ->38
    8     9    >   IS_EQUAL                                                 !3, '%7B'
         10      > JMPNZ                                                    ~8, ->22
    9    11    >   IS_EQUAL                                                 !3, '%5B'
         12      > JMPNZ                                                    ~8, ->22
   10    13    >   IS_EQUAL                                                 !3, '%28'
         14      > JMPNZ                                                    ~8, ->22
   13    15    >   IS_EQUAL                                                 !3, '%7D'
         16      > JMPNZ                                                    ~8, ->25
   14    17    >   IS_EQUAL                                                 !3, '%5D'
         18      > JMPNZ                                                    ~8, ->25
   15    19    >   IS_EQUAL                                                 !3, '%29'
         20      > JMPNZ                                                    ~8, ->25
         21    > > JMP                                                      ->38
   11    22    >   ASSIGN_DIM                                               !2
         23        OP_DATA                                                  !3
   12    24      > JMP                                                      ->39
   16    25    >   COUNT                                            ~10     !2
         26        BOOL_NOT                                         ~11     ~10
         27      > JMPNZ_EX                                         ~11     ~11, ->34
         28    >   INIT_FCALL                                               'array_pop'
         29        SEND_REF                                                 !2
         30        DO_ICALL                                         $12     
         31        FETCH_DIM_R                                      ~13     !1, !3
         32        IS_NOT_EQUAL                                     ~14     $12, ~13
         33        BOOL                                             ~11     ~14
         34    > > JMPZ                                                     ~11, ->37
         35    >   FE_FREE                                                  $7
         36      > RETURN                                                   <false>
   17    37    > > JMP                                                      ->39
   19    38    > > JMP                                                      ->39
    6    39    > > JMP                                                      ->7
         40    >   FE_FREE                                                  $7
   22    41        COUNT                                            ~15     !2
         42        IS_IDENTICAL                                     ~16     ~15, 0
         43      > RETURN                                                   ~16
   23    44*     > RETURN                                                   null

End of function parenthesis

Function check_balanced:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RJftQ
function name:  check_balanced
number of ops:  14
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        NOP                                                      
          2        FAST_CONCAT                                      ~1      !0, '+is+'
          3        INIT_FCALL                                               'parenthesis'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6      > JMPZ                                                     $2, ->9
          7    >   QM_ASSIGN                                        ~3      ''
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~3      'not+'
         10    >   CONCAT                                           ~4      ~1, ~3
         11        CONCAT                                           ~5      ~4, 'balanced%0A'
         12        ECHO                                                     ~5
   27    13      > RETURN                                                   null

End of function check_balanced

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.91 ms | 1012 KiB | 19 Q