3v4l.org

run code in 300+ PHP versions simultaneously
<?php // https://github.com/sugarcrm/sugarcrm_dev/blob/ae189cfa4ed4edd6a4e1e0d9d1d5ec66f46a0b74/include/utils.php#L2082-L2090 function str_begin($str, $begin) { return (substr($str, 0, strlen($begin)) == $begin); } function str_end($str, $end) { return (substr($str, strlen($str) - strlen($end)) == $end); } // Let's test edge cases $funcs = array( 'str_begin', 'str_end', ); $tests = array( // 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 $test) { list($args, $expected) = $test; list($main, $part) = $args; echo $func . '("' . $main . '", "' . $part . '"):' . PHP_EOL; echo " - Expected: "; var_dump($expected); echo " - Actual: "; var_dump($func($main, $part)); echo PHP_EOL; } echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 42
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 42
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 39
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 39
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 39
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/CjiJYj
function name:  (null)
number of ops:  44
compiled vars:  !0 = $funcs, !1 = $tests, !2 = $func, !3 = $test, !4 = $args, !5 = $expected, !6 = $main, !7 = $part
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, <array>
   23     2      > FE_RESET_R                                       $10     !0, ->42
          3    > > FE_FETCH_R                                               $10, !2, ->42
   24     4    > > FE_RESET_R                                       $11     !1, ->39
          5    > > FE_FETCH_R                                               $11, !3, ->39
   25     6    >   QM_ASSIGN                                        ~12     !3
          7        FETCH_LIST_R                                     $13     ~12, 0
          8        ASSIGN                                                   !4, $13
          9        FETCH_LIST_R                                     $15     ~12, 1
         10        ASSIGN                                                   !5, $15
         11        FREE                                                     ~12
   26    12        QM_ASSIGN                                        ~17     !4
         13        FETCH_LIST_R                                     $18     ~17, 0
         14        ASSIGN                                                   !6, $18
         15        FETCH_LIST_R                                     $20     ~17, 1
         16        ASSIGN                                                   !7, $20
         17        FREE                                                     ~17
   27    18        CONCAT                                           ~22     !2, '%28%22'
         19        CONCAT                                           ~23     ~22, !6
         20        CONCAT                                           ~24     ~23, '%22%2C+%22'
         21        CONCAT                                           ~25     ~24, !7
         22        CONCAT                                           ~26     ~25, '%22%29%3A'
         23        CONCAT                                           ~27     ~26, '%0A'
         24        ECHO                                                     ~27
   28    25        ECHO                                                     '+-+Expected%3A+'
         26        INIT_FCALL                                               'var_dump'
         27        SEND_VAR                                                 !5
         28        DO_ICALL                                                 
   29    29        ECHO                                                     '+-+Actual%3A+++'
         30        INIT_FCALL                                               'var_dump'
         31        INIT_DYNAMIC_CALL                                        !2
         32        SEND_VAR_EX                                              !6
         33        SEND_VAR_EX                                              !7
         34        DO_FCALL                                      0  $29     
         35        SEND_VAR                                                 $29
         36        DO_ICALL                                                 
   30    37        ECHO                                                     '%0A'
   24    38      > JMP                                                      ->5
         39    >   FE_FREE                                                  $11
   32    40        ECHO                                                     '%0A'
   23    41      > JMP                                                      ->3
         42    >   FE_FREE                                                  $10
   33    43      > RETURN                                                   1

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

End of function str_begin

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

End of function str_end

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.18 ms | 1400 KiB | 17 Q