3v4l.org

run code in 300+ PHP versions simultaneously
<?php function startsWith($haystack, $needle) { return strncmp($haystack, $needle, strlen($needle)) === 0; } function endsWith($haystack, $needle) { return $needle === '' || substr_compare($haystack, $needle, -strlen($needle)) === 0; } var_dump(startsWith('', '')); var_dump(startsWith('', 'foo')); var_dump(startsWith('foo', '')); var_dump(endsWith('', '')); var_dump(endsWith('', 'foo')); var_dump(endsWith('foo', ''));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HgEcd
function name:  (null)
number of ops:  43
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'startswith'
          2        SEND_VAL                                                 ''
          3        SEND_VAL                                                 ''
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   13     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'startswith'
          9        SEND_VAL                                                 ''
         10        SEND_VAL                                                 'foo'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
   14    14        INIT_FCALL                                               'var_dump'
         15        INIT_FCALL                                               'startswith'
         16        SEND_VAL                                                 'foo'
         17        SEND_VAL                                                 ''
         18        DO_FCALL                                      0  $4      
         19        SEND_VAR                                                 $4
         20        DO_ICALL                                                 
   15    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'endswith'
         23        SEND_VAL                                                 ''
         24        SEND_VAL                                                 ''
         25        DO_FCALL                                      0  $6      
         26        SEND_VAR                                                 $6
         27        DO_ICALL                                                 
   16    28        INIT_FCALL                                               'var_dump'
         29        INIT_FCALL                                               'endswith'
         30        SEND_VAL                                                 ''
         31        SEND_VAL                                                 'foo'
         32        DO_FCALL                                      0  $8      
         33        SEND_VAR                                                 $8
         34        DO_ICALL                                                 
   17    35        INIT_FCALL                                               'var_dump'
         36        INIT_FCALL                                               'endswith'
         37        SEND_VAL                                                 'foo'
         38        SEND_VAL                                                 ''
         39        DO_FCALL                                      0  $10     
         40        SEND_VAR                                                 $10
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

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

End of function startswith

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

End of function endswith

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.39 ms | 1394 KiB | 25 Q