3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stringCheck_TypeSafe(string $string) { $pos = strpos($string, 'cat'); if ($pos === 0) { return true; } return false; } function stringCheck_NotTypeSafe($string) { $pos = strpos($string, 'cat'); if ($pos != 'true') { return true; } return false; } echo "type safe string check, return should be true:\n"; var_dump(stringCheck_TypeSafe('cat')); echo "not type safe string check, return should be true:\n"; var_dump(stringCheck_NotTypeSafe('cat')); echo "not type safe string check, return should be false:\n"; var_dump(stringCheck_NotTypeSafe('a'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gDS9D
function name:  (null)
number of ops:  22
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ECHO                                                     'type+safe+string+check%2C+return+should+be+true%3A%0A'
   26     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'stringcheck_typesafe'
          3        SEND_VAL                                                 'cat'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   27     7        ECHO                                                     'not+type+safe+string+check%2C+return+should+be+true%3A%0A'
   28     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'stringcheck_nottypesafe'
         10        SEND_VAL                                                 'cat'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
   29    14        ECHO                                                     'not+type+safe+string+check%2C+return+should+be+false%3A%0A'
   30    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'stringcheck_nottypesafe'
         17        SEND_VAL                                                 'a'
         18        DO_FCALL                                      0  $4      
         19        SEND_VAR                                                 $4
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Function stringcheck_typesafe:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gDS9D
function name:  stringCheck_TypeSafe
number of ops:  11
compiled vars:  !0 = $string, !1 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'strpos'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'cat'
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
    7     6        IS_IDENTICAL                                             !1, 0
          7      > JMPZ                                                     ~4, ->9
    8     8    > > RETURN                                                   <true>
   11     9    > > RETURN                                                   <false>
   12    10*     > RETURN                                                   null

End of function stringcheck_typesafe

Function stringcheck_nottypesafe:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gDS9D
function name:  stringCheck_NotTypeSafe
number of ops:  11
compiled vars:  !0 = $string, !1 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        INIT_FCALL                                               'strpos'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'cat'
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
   18     6        IS_NOT_EQUAL                                             !1, 'true'
          7      > JMPZ                                                     ~4, ->9
   19     8    > > RETURN                                                   <true>
   22     9    > > RETURN                                                   <false>
   23    10*     > RETURN                                                   null

End of function stringcheck_nottypesafe

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.42 ms | 1403 KiB | 20 Q