3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (defined('HHVM_VERSION')) { exit; } // https://www.mail-archive.com/internals@lists.php.net/msg87079.html function str_begins($a, $b) { return substr_compare($a, $b, 0, strlen($b)) === 0; } function str_ends($a, $b) { return substr_compare($a, $b, -strlen($b)) === 0; } // Let's test edge cases $funcs = [ 'str_begins', 'str_ends', ]; $tests = [ // array(array($main, $part), $expected) array(array("foo", "foo"), true), array(array("foo", ""), true), array(array("", "foo"), false), array(array("", ""), true), ]; foreach ($funcs as $func) { foreach ($tests as list(list($main, $part), $expected)) { echo $func . '(' . var_export($main, true) . ', ' . var_export($part, true) . '):' . PHP_EOL; echo " - Expected: "; var_dump($expected); echo " - Actual: "; var_dump($actual = $func($main, $part)); if ($actual !== $expected) { echo " => DIFF!" . PHP_EOL; } echo PHP_EOL; } echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 3
Branch analysis from position: 2
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 54
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 54
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 51
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 51
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 49
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 49
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 51
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
filename:       /in/AlBBh
function name:  (null)
number of ops:  56
compiled vars:  !0 = $funcs, !1 = $tests, !2 = $func, !3 = $main, !4 = $part, !5 = $expected, !6 = $actual
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DEFINED                                                  'HHVM_VERSION'
          1      > JMPZ                                                     ~7, ->3
    4     2    > > EXIT                                                     
   16     3    >   ASSIGN                                                   !0, <array>
   20     4        ASSIGN                                                   !1, <array>
   27     5      > FE_RESET_R                                       $10     !0, ->54
          6    > > FE_FETCH_R                                               $10, !2, ->54
   28     7    > > FE_RESET_R                                       $11     !1, ->51
          8    > > FE_FETCH_R                                               $11, $12, ->51
          9    >   FETCH_LIST_R                                     $13     $12, 0
         10        FETCH_LIST_R                                     $14     $13, 0
         11        ASSIGN                                                   !3, $14
         12        FETCH_LIST_R                                     $16     $13, 1
         13        ASSIGN                                                   !4, $16
         14        FREE                                                     $13
         15        FETCH_LIST_R                                     $18     $12, 1
         16        ASSIGN                                                   !5, $18
         17        FREE                                                     $12
   29    18        CONCAT                                           ~20     !2, '%28'
         19        INIT_FCALL                                               'var_export'
         20        SEND_VAR                                                 !3
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $21     
         23        CONCAT                                           ~22     ~20, $21
         24        CONCAT                                           ~23     ~22, '%2C+'
         25        INIT_FCALL                                               'var_export'
         26        SEND_VAR                                                 !4
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                         $24     
         29        CONCAT                                           ~25     ~23, $24
         30        CONCAT                                           ~26     ~25, '%29%3A'
         31        CONCAT                                           ~27     ~26, '%0A'
         32        ECHO                                                     ~27
   30    33        ECHO                                                     '+-+Expected%3A+'
         34        INIT_FCALL                                               'var_dump'
         35        SEND_VAR                                                 !5
         36        DO_ICALL                                                 
   31    37        ECHO                                                     '+-+Actual%3A+++'
         38        INIT_FCALL                                               'var_dump'
         39        INIT_DYNAMIC_CALL                                        !2
         40        SEND_VAR_EX                                              !3
         41        SEND_VAR_EX                                              !4
         42        DO_FCALL                                      0  $29     
         43        ASSIGN                                           ~30     !6, $29
         44        SEND_VAL                                                 ~30
         45        DO_ICALL                                                 
   32    46        IS_NOT_IDENTICAL                                         !6, !5
         47      > JMPZ                                                     ~32, ->49
   33    48    >   ECHO                                                     '+%3D%3E+DIFF%21%0A'
   35    49    >   ECHO                                                     '%0A'
   28    50      > JMP                                                      ->8
         51    >   FE_FREE                                                  $11
   37    52        ECHO                                                     '%0A'
   27    53      > JMP                                                      ->6
         54    >   FE_FREE                                                  $10
   38    55      > RETURN                                                   1

Function str_begins:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AlBBh
function name:  str_begins
number of ops:  12
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        INIT_FCALL                                               'substr_compare'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 0
          6        STRLEN                                           ~2      !1
          7        SEND_VAL                                                 ~2
          8        DO_ICALL                                         $3      
          9        IS_IDENTICAL                                     ~4      $3, 0
         10      > RETURN                                                   ~4
   10    11*     > RETURN                                                   null

End of function str_begins

Function str_ends:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AlBBh
function name:  str_ends
number of ops:  12
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        INIT_FCALL                                               'substr_compare'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        STRLEN                                           ~2      !1
          6        MUL                                              ~3      ~2, -1
          7        SEND_VAL                                                 ~3
          8        DO_ICALL                                         $4      
          9        IS_IDENTICAL                                     ~5      $4, 0
         10      > RETURN                                                   ~5
   13    11*     > RETURN                                                   null

End of function str_ends

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.52 ms | 1404 KiB | 19 Q