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) { var_dump($char);die(); 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; } $cont = 'Number of items: 0'; echo "Usually works:\n"; $str = 'not-existing'; var_dump(containsString($str, $cont)); var_dump(containsString_mlocati($str, $cont)); $str = 'items'; var_dump(containsString($str, $cont)); var_dump(containsString_mlocati($str, $cont)); echo "\n\n"; echo "**BUT:\n"; $str = '0'; var_dump(containsString($str, $cont)); var_dump(containsString_mlocati($str, $cont));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/krHTH
function name:  (null)
number of ops:  53
compiled vars:  !0 = $cont, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
   25     3        ASSIGN                                                   !0, 'Number+of+items%3A+0'
   26     4        ECHO                                                     'Usually+works%3A%0A'
   27     5        ASSIGN                                                   !1, 'not-existing'
   28     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'containsstring'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $5      
         11        SEND_VAR                                                 $5
         12        DO_ICALL                                                 
   29    13        INIT_FCALL                                               'var_dump'
         14        INIT_FCALL                                               'containsstring_mlocati'
         15        SEND_VAR                                                 !1
         16        SEND_VAR                                                 !0
         17        DO_FCALL                                      0  $7      
         18        SEND_VAR                                                 $7
         19        DO_ICALL                                                 
   30    20        ASSIGN                                                   !1, 'items'
   31    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'containsstring'
         23        SEND_VAR                                                 !1
         24        SEND_VAR                                                 !0
         25        DO_FCALL                                      0  $10     
         26        SEND_VAR                                                 $10
         27        DO_ICALL                                                 
   32    28        INIT_FCALL                                               'var_dump'
         29        INIT_FCALL                                               'containsstring_mlocati'
         30        SEND_VAR                                                 !1
         31        SEND_VAR                                                 !0
         32        DO_FCALL                                      0  $12     
         33        SEND_VAR                                                 $12
         34        DO_ICALL                                                 
   33    35        ECHO                                                     '%0A%0A'
   34    36        ECHO                                                     '%2A%2ABUT%3A%0A'
   35    37        ASSIGN                                                   !1, '0'
   36    38        INIT_FCALL                                               'var_dump'
         39        INIT_FCALL                                               'containsstring'
         40        SEND_VAR                                                 !1
         41        SEND_VAR                                                 !0
         42        DO_FCALL                                      0  $15     
         43        SEND_VAR                                                 $15
         44        DO_ICALL                                                 
   37    45        INIT_FCALL                                               'var_dump'
         46        INIT_FCALL                                               'containsstring_mlocati'
         47        SEND_VAR                                                 !1
         48        SEND_VAR                                                 !0
         49        DO_FCALL                                      0  $17     
         50        SEND_VAR                                                 $17
         51        DO_ICALL                                                 
         52      > 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 = 24
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 24
Branch analysis from position: 11
Branch analysis from position: 24
filename:       /in/krHTH
function name:  containsString
number of ops:  27
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, ->24
         11    > > FE_FETCH_R                                               $9, !3, ->24
    6    12    >   INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                                 
         15      > EXIT                                                     
    7    16*       INIT_FCALL                                               'strstr'
         17*       SEND_VAR                                                 !0
         18*       SEND_VAR                                                 !3
         19*       DO_ICALL                                         $11     
         20*       JMPZ                                                     $11, ->23
    8    21*       FE_FREE                                                  $9
         22*       RETURN                                                   <true>
    5    23*       JMP                                                      ->11
         24    >   FE_FREE                                                  $9
   11    25      > RETURN                                                   <false>
   12    26*     > 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/krHTH
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
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   16     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
   17     9      > FE_RESET_R                                       $8      !2, ->20
         10    > > FE_FETCH_R                                               $8, !3, ->20
   18    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
   19    17    >   FE_FREE                                                  $8
         18      > RETURN                                                   <true>
   17    19    > > JMP                                                      ->10
         20    >   FE_FREE                                                  $8
   22    21      > RETURN                                                   <false>
   23    22*     > RETURN                                                   null

End of function containsstring_mlocati

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.07 ms | 1398 KiB | 25 Q