3v4l.org

run code in 300+ PHP versions simultaneously
<?php function foo1($string, $with) { if (!$bytes = strlen($with)) { return true; } // Warning check, see http://php.net/manual/en/function.substr-compare.php#refsect1-function.substr-compare-returnvalues if (strlen($string) < $bytes) { return false; } return substr_compare($string, $with, -$bytes); } function foo2($string, $with) { if (!$bytes = strlen($with)) { return true; } // Warning check, see http://php.net/manual/en/function.substr-compare.php#refsect1-function.substr-compare-returnvalues if (strlen($string) < $bytes) { return false; } return substr_compare($string, $with, -$bytes, $bytes); } var_dump(foo1('a', 'a')); var_dump(foo2('a', 'a')); var_dump(foo1('', '')); var_dump(foo2('', '')); var_dump(foo1('a', '')); var_dump(foo2('a', '')); var_dump(foo1('', 'a')); var_dump(foo2('', 'a'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ktTvQ
function name:  (null)
number of ops:  57
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'foo1'
          2        SEND_VAL                                                 'a'
          3        SEND_VAL                                                 'a'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   28     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'foo2'
          9        SEND_VAL                                                 'a'
         10        SEND_VAL                                                 'a'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
   29    14        INIT_FCALL                                               'var_dump'
         15        INIT_FCALL                                               'foo1'
         16        SEND_VAL                                                 ''
         17        SEND_VAL                                                 ''
         18        DO_FCALL                                      0  $4      
         19        SEND_VAR                                                 $4
         20        DO_ICALL                                                 
   30    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'foo2'
         23        SEND_VAL                                                 ''
         24        SEND_VAL                                                 ''
         25        DO_FCALL                                      0  $6      
         26        SEND_VAR                                                 $6
         27        DO_ICALL                                                 
   31    28        INIT_FCALL                                               'var_dump'
         29        INIT_FCALL                                               'foo1'
         30        SEND_VAL                                                 'a'
         31        SEND_VAL                                                 ''
         32        DO_FCALL                                      0  $8      
         33        SEND_VAR                                                 $8
         34        DO_ICALL                                                 
   32    35        INIT_FCALL                                               'var_dump'
         36        INIT_FCALL                                               'foo2'
         37        SEND_VAL                                                 'a'
         38        SEND_VAL                                                 ''
         39        DO_FCALL                                      0  $10     
         40        SEND_VAR                                                 $10
         41        DO_ICALL                                                 
   33    42        INIT_FCALL                                               'var_dump'
         43        INIT_FCALL                                               'foo1'
         44        SEND_VAL                                                 ''
         45        SEND_VAL                                                 'a'
         46        DO_FCALL                                      0  $12     
         47        SEND_VAR                                                 $12
         48        DO_ICALL                                                 
   34    49        INIT_FCALL                                               'var_dump'
         50        INIT_FCALL                                               'foo2'
         51        SEND_VAL                                                 ''
         52        SEND_VAL                                                 'a'
         53        DO_FCALL                                      0  $14     
         54        SEND_VAR                                                 $14
         55        DO_ICALL                                                 
         56      > RETURN                                                   1

Function foo1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ktTvQ
function name:  foo1
number of ops:  19
compiled vars:  !0 = $string, !1 = $with, !2 = $bytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        STRLEN                                           ~3      !1
          3        ASSIGN                                           ~4      !2, ~3
          4        BOOL_NOT                                         ~5      ~4
          5      > JMPZ                                                     ~5, ->7
    6     6    > > RETURN                                                   <true>
    9     7    >   STRLEN                                           ~6      !0
          8        IS_SMALLER                                               ~6, !2
          9      > JMPZ                                                     ~7, ->11
   10    10    > > RETURN                                                   <false>
   12    11    >   INIT_FCALL                                               'substr_compare'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !1
         14        MUL                                              ~8      !2, -1
         15        SEND_VAL                                                 ~8
         16        DO_ICALL                                         $9      
         17      > RETURN                                                   $9
   13    18*     > RETURN                                                   null

End of function foo1

Function foo2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ktTvQ
function name:  foo2
number of ops:  20
compiled vars:  !0 = $string, !1 = $with, !2 = $bytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        STRLEN                                           ~3      !1
          3        ASSIGN                                           ~4      !2, ~3
          4        BOOL_NOT                                         ~5      ~4
          5      > JMPZ                                                     ~5, ->7
   18     6    > > RETURN                                                   <true>
   21     7    >   STRLEN                                           ~6      !0
          8        IS_SMALLER                                               ~6, !2
          9      > JMPZ                                                     ~7, ->11
   22    10    > > RETURN                                                   <false>
   24    11    >   INIT_FCALL                                               'substr_compare'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !1
         14        MUL                                              ~8      !2, -1
         15        SEND_VAL                                                 ~8
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $9      
         18      > RETURN                                                   $9
   25    19*     > RETURN                                                   null

End of function foo2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171 ms | 1407 KiB | 25 Q