3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); function containsString($str, $cont = array()) { $arr = ( ! is_array($cont)) ? array($cont) : $cont; // turn the string into an array foreach ($arr as $char) { if (strstr($str, $char)) { return true; } } return false; } function containsString_mlocati($str, $cont = array()) { $arr = is_array($cont) ? $cont : array($cont); foreach($arr as $item) { if(strstr($str, $item) !== false) { return true; } } return false; } $str = 'Number of items: 0'; echo "Usually works:\n"; $cont = 'not-existing'; echo 'Your: ', var_dump(containsString($str, $cont)); echo 'Mine: ', var_dump(containsString_mlocati($str, $cont)); $cont = 'items'; echo 'Your: ', var_dump(containsString($str, $cont)); echo 'Mine: ', var_dump(containsString_mlocati($str, $cont)); echo "\n\n"; echo "**BUT:\n"; $cont = '0'; echo 'Your: ', var_dump(containsString($str, $cont)); echo 'Mine: ', var_dump(containsString_mlocati($str, $cont));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JjcN0
function name:  (null)
number of ops:  65
compiled vars:  !0 = $str, !1 = $cont
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
   24     3        ASSIGN                                                   !0, 'Number+of+items%3A+0'
   25     4        ECHO                                                     'Usually+works%3A%0A'
   26     5        ASSIGN                                                   !1, 'not-existing'
   27     6        ECHO                                                     'Your%3A+'
          7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'containsstring'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $5      
         12        SEND_VAR                                                 $5
         13        DO_ICALL                                         $6      
         14        ECHO                                                     $6
   28    15        ECHO                                                     'Mine%3A+'
         16        INIT_FCALL                                               'var_dump'
         17        INIT_FCALL                                               'containsstring_mlocati'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !1
         20        DO_FCALL                                      0  $7      
         21        SEND_VAR                                                 $7
         22        DO_ICALL                                         $8      
         23        ECHO                                                     $8
   29    24        ASSIGN                                                   !1, 'items'
   30    25        ECHO                                                     'Your%3A+'
         26        INIT_FCALL                                               'var_dump'
         27        INIT_FCALL                                               'containsstring'
         28        SEND_VAR                                                 !0
         29        SEND_VAR                                                 !1
         30        DO_FCALL                                      0  $10     
         31        SEND_VAR                                                 $10
         32        DO_ICALL                                         $11     
         33        ECHO                                                     $11
   31    34        ECHO                                                     'Mine%3A+'
         35        INIT_FCALL                                               'var_dump'
         36        INIT_FCALL                                               'containsstring_mlocati'
         37        SEND_VAR                                                 !0
         38        SEND_VAR                                                 !1
         39        DO_FCALL                                      0  $12     
         40        SEND_VAR                                                 $12
         41        DO_ICALL                                         $13     
         42        ECHO                                                     $13
   32    43        ECHO                                                     '%0A%0A'
   33    44        ECHO                                                     '%2A%2ABUT%3A%0A'
   34    45        ASSIGN                                                   !1, '0'
   35    46        ECHO                                                     'Your%3A+'
         47        INIT_FCALL                                               'var_dump'
         48        INIT_FCALL                                               'containsstring'
         49        SEND_VAR                                                 !0
         50        SEND_VAR                                                 !1
         51        DO_FCALL                                      0  $15     
         52        SEND_VAR                                                 $15
         53        DO_ICALL                                         $16     
         54        ECHO                                                     $16
   36    55        ECHO                                                     'Mine%3A+'
         56        INIT_FCALL                                               'var_dump'
         57        INIT_FCALL                                               'containsstring_mlocati'
         58        SEND_VAR                                                 !0
         59        SEND_VAR                                                 !1
         60        DO_FCALL                                      0  $17     
         61        SEND_VAR                                                 $17
         62        DO_ICALL                                         $18     
         63        ECHO                                                     $18
         64      > RETURN                                                   1

Function containsstring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
Branch analysis from position: 20
filename:       /in/JjcN0
function name:  containsString
number of ops:  23
compiled vars:  !0 = $str, !1 = $cont, !2 = $arr, !3 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    4     2        TYPE_CHECK                                  128  ~4      !1
          3        BOOL_NOT                                         ~5      ~4
          4      > JMPZ                                                     ~5, ->8
          5    >   INIT_ARRAY                                       ~6      !1
          6        QM_ASSIGN                                        ~7      ~6
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~7      !1
          9    >   ASSIGN                                                   !2, ~7
    5    10      > FE_RESET_R                                       $9      !2, ->20
         11    > > FE_FETCH_R                                               $9, !3, ->20
    6    12    >   INIT_FCALL                                               'strstr'
         13        SEND_VAR                                                 !0
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                         $10     
         16      > JMPZ                                                     $10, ->19
    7    17    >   FE_FREE                                                  $9
         18      > RETURN                                                   <true>
    5    19    > > JMP                                                      ->11
         20    >   FE_FREE                                                  $9
   10    21      > RETURN                                                   <false>
   11    22*     > RETURN                                                   null

End of function containsstring

Function containsstring_mlocati:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 20
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 20
Branch analysis from position: 10
Branch analysis from position: 20
filename:       /in/JjcN0
function name:  containsString_mlocati
number of ops:  23
compiled vars:  !0 = $str, !1 = $cont, !2 = $arr, !3 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   15     2        TYPE_CHECK                                  128          !1
          3      > JMPZ                                                     ~4, ->6
          4    >   QM_ASSIGN                                        ~5      !1
          5      > JMP                                                      ->8
          6    >   INIT_ARRAY                                       ~6      !1
          7        QM_ASSIGN                                        ~5      ~6
          8    >   ASSIGN                                                   !2, ~5
   16     9      > FE_RESET_R                                       $8      !2, ->20
         10    > > FE_FETCH_R                                               $8, !3, ->20
   17    11    >   INIT_FCALL                                               'strstr'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $9      
         15        TYPE_CHECK                                  1018          $9
         16      > JMPZ                                                     ~10, ->19
   18    17    >   FE_FREE                                                  $8
         18      > RETURN                                                   <true>
   16    19    > > JMP                                                      ->10
         20    >   FE_FREE                                                  $8
   21    21      > RETURN                                                   <false>
   22    22*     > RETURN                                                   null

End of function containsstring_mlocati

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
291.06 ms | 1407 KiB | 26 Q