3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isCorrect($string) { $len = strlen($string); $stack = array(); for( $i = 0; $i < $len; ++$i) { if ( $string[$i] == '(' ) array_push($stack, $string[$i]); elseif( $string[$i] == ')' ) { if ( empty($stack) === false ) array_pop($stack); else return false; } } return empty($stack); } $string = '((()))'; isCorrect($string); //var_dump(isCorrect($string)); //var_dump(strlen($string) % 2); //assert(isCorrect('') === true); //assert(isCorrect('()') === true); //assert(isCorrect('{()}') === true); //assert(isCorrect('{()}{}') === true); //assert(isCorrect('(())') === true); //assert(isCorrect('{({({({()})})})}') === true); //assert(isCorrect('{(})') === false);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0moKK
function name:  (null)
number of ops:  5
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, '%28%28%28%29%29%29'
   18     1        INIT_FCALL                                               'iscorrect'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
   28     4      > RETURN                                                   1

Function iscorrect:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 6
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 6
Branch analysis from position: 29
Branch analysis from position: 6
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/0moKK
function name:  isCorrect
number of ops:  32
compiled vars:  !0 = $string, !1 = $len, !2 = $stack, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        STRLEN                                           ~4      !0
          2        ASSIGN                                                   !1, ~4
    4     3        ASSIGN                                                   !2, <array>
    5     4        ASSIGN                                                   !3, 0
          5      > JMP                                                      ->27
    7     6    >   FETCH_DIM_R                                      ~8      !0, !3
          7        IS_EQUAL                                                 ~8, '%28'
          8      > JMPZ                                                     ~9, ->15
          9    >   INIT_FCALL                                               'array_push'
         10        SEND_REF                                                 !2
         11        FETCH_DIM_R                                      ~10     !0, !3
         12        SEND_VAL                                                 ~10
         13        DO_ICALL                                                 
         14      > JMP                                                      ->26
    8    15    >   FETCH_DIM_R                                      ~12     !0, !3
         16        IS_EQUAL                                                 ~12, '%29'
         17      > JMPZ                                                     ~13, ->26
   10    18    >   ISSET_ISEMPTY_CV                                 ~14     !2
         19        TYPE_CHECK                                    4          ~14
         20      > JMPZ                                                     ~15, ->25
         21    >   INIT_FCALL                                               'array_pop'
         22        SEND_REF                                                 !2
         23        DO_ICALL                                                 
         24      > JMP                                                      ->26
   11    25    > > RETURN                                                   <false>
    5    26    >   PRE_INC                                                  !3
         27    >   IS_SMALLER                                               !3, !1
         28      > JMPNZ                                                    ~18, ->6
   15    29    >   ISSET_ISEMPTY_CV                                 ~19     !2
         30      > RETURN                                                   ~19
   16    31*     > RETURN                                                   null

End of function iscorrect

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.56 ms | 1403 KiB | 18 Q