3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Finds whether a single character among a list of characters is in a string * * @param string $haystack The string where char_list is looked for. * @param string $char_list Case sensitive set of characters to look for. * @return bool */ function contains_allowed( string $haystack, string $char_list ) : bool { if( '' === $char_list ) return true; if( '' === $haystack ) return false; return strcspn( $haystack, $char_list ) !== strlen( $haystack ); } $tests = [ [ 'haystack' => '', 'char_list' => '' , 'expect' => true ], [ 'haystack' => '', 'char_list' => 'r', 'expect' => false ], [ 'haystack' => 'r', 'char_list' => '' , 'expect' => true ], [ 'haystack' => 'r', 'char_list' => 'r+', 'expect' => true ], [ 'haystack' => 'r+', 'char_list' => 'r+', 'expect' => true ], [ 'haystack' => 'w', 'char_list' => 'r+', 'expect' => false ], [ 'haystack' => 'w+', 'char_list' => 'r+', 'expect' => true ], ]; foreach( $tests as $test => $args ) assert( contains_allowed( $args[ 'haystack' ], $args[ 'char_list' ] ) === $args[ 'expect' ], "Failed test #$test" );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 20
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 20
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/0C6sQ
function name:  (null)
number of ops:  22
compiled vars:  !0 = $tests, !1 = $args, !2 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   34     1      > FE_RESET_R                                       $4      !0, ->20
          2    > > FE_FETCH_R                                       ~5      $4, !1, ->20
          3    >   ASSIGN                                                   !2, ~5
   35     4        ASSERT_CHECK                                             
          5        INIT_FCALL                                               'assert'
   36     6        INIT_FCALL                                               'contains_allowed'
          7        FETCH_DIM_R                                      ~7      !1, 'haystack'
          8        SEND_VAL                                                 ~7
          9        FETCH_DIM_R                                      ~8      !1, 'char_list'
         10        SEND_VAL                                                 ~8
         11        DO_FCALL                                      0  $9      
         12        FETCH_DIM_R                                      ~10     !1, 'expect'
         13        IS_IDENTICAL                                     ~11     $9, ~10
         14        SEND_VAL                                                 ~11
   37    15        NOP                                                      
         16        FAST_CONCAT                                      ~12     'Failed+test+%23', !2
         17        SEND_VAL                                                 ~12
         18        DO_ICALL                                                 
   34    19      > JMP                                                      ->2
         20    >   FE_FREE                                                  $4
   38    21      > RETURN                                                   1

Function contains_allowed:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0C6sQ
function name:  contains_allowed
number of ops:  18
compiled vars:  !0 = $haystack, !1 = $char_list
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        IS_IDENTICAL                                             !1, ''
          3      > JMPZ                                                     ~2, ->5
          4    > > RETURN                                                   <true>
   14     5    >   IS_IDENTICAL                                             !0, ''
          6      > JMPZ                                                     ~3, ->8
          7    > > RETURN                                                   <false>
   16     8    >   INIT_FCALL                                               'strcspn'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $4      
         12        STRLEN                                           ~5      !0
         13        IS_NOT_IDENTICAL                                 ~6      $4, ~5
         14        VERIFY_RETURN_TYPE                                       ~6
         15      > RETURN                                                   ~6
   17    16*       VERIFY_RETURN_TYPE                                       
         17*     > RETURN                                                   null

End of function contains_allowed

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.28 ms | 1403 KiB | 18 Q