3v4l.org

run code in 300+ PHP versions simultaneously
<?php $haystack = "I like cats."; $needles = ['cat' => 0, 'dog' => 1]; function inefficient(string $haystack, array $needles) { $qualifiers = array_filter( $needles, fn($k) => strpos($haystack, $k) !== false, ARRAY_FILTER_USE_KEY ); if (!$qualifiers) { throw new Exception('No needles were found in the haystack'); } return current($qualifiers); } try { var_export(inefficient($haystack, $needles)); } catch (Exception $e) { echo $e->getMessage(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 10
Branch analysis from position: 10
2 jumps found. (Code = 107) Position 1 = 11, Position 2 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qt5Nf
function name:  (null)
number of ops:  15
compiled vars:  !0 = $haystack, !1 = $needles, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'I+like+cats.'
    4     1        ASSIGN                                                   !1, <array>
   18     2        INIT_FCALL                                               'var_export'
          3        INIT_FCALL                                               'inefficient'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $5      
          7        SEND_VAR                                                 $5
          8        DO_ICALL                                                 
          9      > JMP                                                      ->14
   19    10  E > > CATCH                                       last         'Exception'
   20    11    >   INIT_METHOD_CALL                                         !2, 'getMessage'
         12        DO_FCALL                                      0  $7      
         13        ECHO                                                     $7
   21    14    > > RETURN                                                   1

Function inefficient:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qt5Nf
function name:  inefficient
number of ops:  21
compiled vars:  !0 = $haystack, !1 = $needles, !2 = $qualifiers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        INIT_FCALL                                               'array_filter'
    8     3        SEND_VAR                                                 !1
    9     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQt5Nf%3A9%240'
          5        BIND_LEXICAL                                             ~3, !0
          6        SEND_VAL                                                 ~3
   10     7        SEND_VAL                                                 2
          8        DO_ICALL                                         $4      
    7     9        ASSIGN                                                   !2, $4
   12    10        BOOL_NOT                                         ~6      !2
         11      > JMPZ                                                     ~6, ->16
   13    12    >   NEW                                              $7      'Exception'
         13        SEND_VAL_EX                                              'No+needles+were+found+in+the+haystack'
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $7
   15    16    >   INIT_FCALL                                               'current'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $9      
         19      > RETURN                                                   $9
   16    20*     > RETURN                                                   null

End of function inefficient

Function %00%7Bclosure%7D%2Fin%2FQt5Nf%3A9%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qt5Nf
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $k, !1 = $haystack
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_FCALL                                               'strpos'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        TYPE_CHECK                                  1018  ~3      $2
          7      > RETURN                                                   ~3
          8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQt5Nf%3A9%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
129.35 ms | 1407 KiB | 22 Q