3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('str_contains')) { function str_contains(string $haystack, string $needle): bool { return '' === $needle || false !== strpos($haystack, $needle); } } if (!function_exists('str_ends_with')) { function str_ends_with(string $haystack, string $needle): bool { return '' === $needle || ('' !== $haystack && 0 === \substr_compare($haystack, $needle, -\strlen($needle))); } } if (!function_exists('str_starts_with')) { function str_starts_with(string $haystack, string $needle): bool { return 0 === \strncmp($haystack, $needle, \strlen($needle)); } } $methods = [ 'str_contains', 'str_starts_with', 'str_ends_with', ]; $types = [ 'string' => 'test', 'int' => 1, 'float' => 1.23, 'null' => null, 'true' => true, 'false' => false, 'object' => new StdClass(), 'array' => [], ]; $result = []; foreach ($methods as $method) { foreach ($types as $type => $val) { foreach (['first' => [$val, 'test'], 'second' => ['test', $val]] as $firstSecond => $args) { try { $res = $method(...$args); } catch (Error $e) { $res = 'Fatal error triggered'; } $result[$method][$type][$firstSecond] = $res; } } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 62
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 62
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 34, Position 2 = 60
Branch analysis from position: 34
2 jumps found. (Code = 78) Position 1 = 35, Position 2 = 60
Branch analysis from position: 35
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 58
Branch analysis from position: 43
2 jumps found. (Code = 78) Position 1 = 44, Position 2 = 58
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 58
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 60
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
Branch analysis from position: 18
Branch analysis from position: 12
Branch analysis from position: 6
Found catch point at position: 51
Branch analysis from position: 51
2 jumps found. (Code = 107) Position 1 = 52, Position 2 = -2
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
filename:       /in/m8OIn
function name:  (null)
number of ops:  67
compiled vars:  !0 = $methods, !1 = $types, !2 = $result, !3 = $method, !4 = $val, !5 = $type, !6 = $args, !7 = $firstSecond, !8 = $res, !9 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'str_contains'
          2        DO_ICALL                                         $10     
          3        BOOL_NOT                                         ~11     $10
          4      > JMPZ                                                     ~11, ->6
    5     5    >   DECLARE_FUNCTION                                         'str_contains'
   10     6    >   INIT_FCALL                                               'function_exists'
          7        SEND_VAL                                                 'str_ends_with'
          8        DO_ICALL                                         $12     
          9        BOOL_NOT                                         ~13     $12
         10      > JMPZ                                                     ~13, ->12
   12    11    >   DECLARE_FUNCTION                                         'str_ends_with'
   17    12    >   INIT_FCALL                                               'function_exists'
         13        SEND_VAL                                                 'str_starts_with'
         14        DO_ICALL                                         $14     
         15        BOOL_NOT                                         ~15     $14
         16      > JMPZ                                                     ~15, ->18
   19    17    >   DECLARE_FUNCTION                                         'str_starts_with'
   25    18    >   ASSIGN                                                   !0, <array>
   32    19        INIT_ARRAY                                       ~17     'test', 'string'
   33    20        ADD_ARRAY_ELEMENT                                ~17     1, 'int'
   34    21        ADD_ARRAY_ELEMENT                                ~17     1.23, 'float'
   32    22        ADD_ARRAY_ELEMENT                                ~17     null, 'null'
         23        ADD_ARRAY_ELEMENT                                ~17     <true>, 'true'
         24        ADD_ARRAY_ELEMENT                                ~17     <false>, 'false'
   38    25        NEW                                              $18     'StdClass'
         26        DO_FCALL                                      0          
         27        ADD_ARRAY_ELEMENT                                ~17     $18, 'object'
   32    28        ADD_ARRAY_ELEMENT                                ~17     <array>, 'array'
   31    29        ASSIGN                                                   !1, ~17
   42    30        ASSIGN                                                   !2, <array>
   45    31      > FE_RESET_R                                       $22     !0, ->62
         32    > > FE_FETCH_R                                               $22, !3, ->62
   47    33    > > FE_RESET_R                                       $23     !1, ->60
         34    > > FE_FETCH_R                                       ~24     $23, !4, ->60
         35    >   ASSIGN                                                   !5, ~24
   49    36        INIT_ARRAY                                       ~26     !4
         37        ADD_ARRAY_ELEMENT                                ~26     'test'
         38        INIT_ARRAY                                       ~27     ~26, 'first'
         39        INIT_ARRAY                                       ~28     'test'
         40        ADD_ARRAY_ELEMENT                                ~28     !4
         41        ADD_ARRAY_ELEMENT                                ~27     ~28, 'second'
         42      > FE_RESET_R                                       $29     ~27, ->58
         43    > > FE_FETCH_R                                       ~30     $29, !6, ->58
         44    >   ASSIGN                                                   !7, ~30
   53    45        INIT_DYNAMIC_CALL                                        !3
         46        SEND_UNPACK                                              !6
         47        CHECK_UNDEF_ARGS                                         
         48        DO_FCALL                                      1  $32     
         49        ASSIGN                                                   !8, $32
         50      > JMP                                                      ->53
   55    51  E > > CATCH                                       last         'Error'
   57    52    >   ASSIGN                                                   !8, 'Fatal+error+triggered'
   60    53    >   FETCH_DIM_W                                      $35     !2, !3
         54        FETCH_DIM_W                                      $36     $35, !5
         55        ASSIGN_DIM                                               $36, !7
         56        OP_DATA                                                  !8
   49    57      > JMP                                                      ->43
         58    >   FE_FREE                                                  $29
   47    59      > JMP                                                      ->34
         60    >   FE_FREE                                                  $23
   45    61      > JMP                                                      ->32
         62    >   FE_FREE                                                  $22
   65    63        INIT_FCALL                                               'var_export'
         64        SEND_VAR                                                 !2
         65        DO_ICALL                                                 
         66      > RETURN                                                   1

Function %00str_contains%2Fin%2Fm8OIn%3A5%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/m8OIn
function name:  str_contains
number of ops:  14
compiled vars:  !0 = $haystack, !1 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        IS_IDENTICAL                                     ~2      !1, ''
          3      > JMPNZ_EX                                         ~2      ~2, ->10
          4    >   INIT_FCALL                                               'strpos'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $3      
          8        TYPE_CHECK                                  1018  ~4      $3
          9        BOOL                                             ~2      ~4
         10    >   VERIFY_RETURN_TYPE                                       ~2
         11      > RETURN                                                   ~2
    8    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function %00str_contains%2Fin%2Fm8OIn%3A5%240

Function %00str_ends_with%2Fin%2Fm8OIn%3A12%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 16
filename:       /in/m8OIn
function name:  str_ends_with
number of ops:  20
compiled vars:  !0 = $haystack, !1 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        IS_IDENTICAL                                     ~2      !1, ''
          3      > JMPNZ_EX                                         ~2      ~2, ->16
          4    >   IS_NOT_IDENTICAL                                 ~3      !0, ''
          5      > JMPZ_EX                                          ~3      ~3, ->15
          6    >   INIT_FCALL                                               'substr_compare'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        STRLEN                                           ~4      !1
         10        MUL                                              ~5      ~4, -1
         11        SEND_VAL                                                 ~5
         12        DO_ICALL                                         $6      
         13        IS_IDENTICAL                                     ~7      $6, 0
         14        BOOL                                             ~3      ~7
         15    >   BOOL                                             ~2      ~3
         16    >   VERIFY_RETURN_TYPE                                       ~2
         17      > RETURN                                                   ~2
   15    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of function %00str_ends_with%2Fin%2Fm8OIn%3A12%241

Function %00str_starts_with%2Fin%2Fm8OIn%3A19%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m8OIn
function name:  str_starts_with
number of ops:  13
compiled vars:  !0 = $haystack, !1 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     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        VERIFY_RETURN_TYPE                                       ~4
         10      > RETURN                                                   ~4
   22    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function %00str_starts_with%2Fin%2Fm8OIn%3A19%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.36 ms | 1419 KiB | 23 Q