3v4l.org

run code in 300+ PHP versions simultaneously
<?php test('()'); test('())'); test('(())'); test('))(('); test(')('); test(')(('); test('((()('); test('((()()(())))'); test('((()()(()))'); test('foo((bar)is(((baz))and)quix)'); function test($str) { echo "$str is ".(is_balanced($str)?'balanced':'not balanced')."\n"; } function is_balanced($str) { $count = 0; for($i=0;$i<strlen($str);$i++) { switch($str[$i]) { case '(': $count++; break; case ')': $count--; if($count < 0) return false; // ignore everything else } } return $count == 0; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vOdCj
function name:  (null)
number of ops:  31
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL_BY_NAME                                       'test'
          1        SEND_VAL_EX                                              '%28%29'
          2        DO_FCALL                                      0          
    4     3        INIT_FCALL_BY_NAME                                       'test'
          4        SEND_VAL_EX                                              '%28%29%29'
          5        DO_FCALL                                      0          
    5     6        INIT_FCALL_BY_NAME                                       'test'
          7        SEND_VAL_EX                                              '%28%28%29%29'
          8        DO_FCALL                                      0          
    6     9        INIT_FCALL_BY_NAME                                       'test'
         10        SEND_VAL_EX                                              '%29%29%28%28'
         11        DO_FCALL                                      0          
    7    12        INIT_FCALL_BY_NAME                                       'test'
         13        SEND_VAL_EX                                              '%29%28'
         14        DO_FCALL                                      0          
    8    15        INIT_FCALL_BY_NAME                                       'test'
         16        SEND_VAL_EX                                              '%29%28%28'
         17        DO_FCALL                                      0          
    9    18        INIT_FCALL_BY_NAME                                       'test'
         19        SEND_VAL_EX                                              '%28%28%28%29%28'
         20        DO_FCALL                                      0          
   10    21        INIT_FCALL_BY_NAME                                       'test'
         22        SEND_VAL_EX                                              '%28%28%28%29%28%29%28%28%29%29%29%29'
         23        DO_FCALL                                      0          
   11    24        INIT_FCALL_BY_NAME                                       'test'
         25        SEND_VAL_EX                                              '%28%28%28%29%28%29%28%28%29%29%29'
         26        DO_FCALL                                      0          
   12    27        INIT_FCALL_BY_NAME                                       'test'
         28        SEND_VAL_EX                                              'foo%28%28bar%29is%28%28%28baz%29%29and%29quix%29'
         29        DO_FCALL                                      0          
   35    30      > RETURN                                                   1

Function test:
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/vOdCj
function name:  test
number of ops:  14
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        NOP                                                      
          2        FAST_CONCAT                                      ~1      !0, '+is+'
          3        INIT_FCALL_BY_NAME                                       'is_balanced'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $2      
          6      > JMPZ                                                     $2, ->9
          7    >   QM_ASSIGN                                        ~3      'balanced'
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~3      'not+balanced'
         10    >   CONCAT                                           ~4      ~1, ~3
         11        CONCAT                                           ~5      ~4, '%0A'
         12        ECHO                                                     ~5
   16    13      > RETURN                                                   null

End of function test

Function is_balanced:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
4 jumps found. (Code = 188) Position 1 = 11, Position 2 = 13, Position 3 = 18, Position 4 = 6
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
Branch analysis from position: 4
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 18
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 13
Branch analysis from position: 11
filename:       /in/vOdCj
function name:  is_balanced
number of ops:  26
compiled vars:  !0 = $str, !1 = $count, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        ASSIGN                                                   !1, 0
   22     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->20
   23     4    >   FETCH_DIM_R                                      ~5      !0, !2
          5      > SWITCH_STRING                                            ~5, [ '%28':->11, '%29':->13, ], ->18
   24     6    >   CASE                                                     ~5, '%28'
          7      > JMPNZ                                                    ~6, ->11
   27     8    >   CASE                                                     ~5, '%29'
          9      > JMPNZ                                                    ~6, ->13
         10    > > JMP                                                      ->18
   25    11    >   PRE_INC                                                  !1
   26    12      > JMP                                                      ->18
   28    13    >   PRE_DEC                                                  !1
   29    14        IS_SMALLER                                               !1, 0
         15      > JMPZ                                                     ~9, ->18
         16    >   FREE                                                     ~5
         17      > RETURN                                                   <false>
         18    >   FREE                                                     ~5
   22    19        PRE_INC                                                  !2
         20    >   STRLEN                                           ~11     !0
         21        IS_SMALLER                                               !2, ~11
         22      > JMPNZ                                                    ~12, ->4
   33    23    >   IS_EQUAL                                         ~13     !1, 0
         24      > RETURN                                                   ~13
   35    25*     > RETURN                                                   null

End of function is_balanced

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.42 ms | 1407 KiB | 13 Q