3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class ArrayUtils { private static $visited = []; private static $sum = 0; private static $data = []; public static function containsSum(array $data, int $sum): bool { self::$data = $data; self::$sum = $sum; self::$visited = []; return self::found(); } private static function found(): bool { if (! self::$data) { return false; } $value = array_pop(self::$data); if (isset(self::$visited[self::$sum - $value])) { return true; } self::$visited[$value] = true; return self::found(); } } $data = range(0, 49999); shuffle($data); var_dump(ArrayUtils::containsSum($data, 1220)); var_dump(ArrayUtils::containsSum($data, -7));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VJf7L
function name:  (null)
number of ops:  23
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 49999
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   38     5        INIT_FCALL                                               'shuffle'
          6        SEND_REF                                                 !0
          7        DO_ICALL                                                 
   39     8        INIT_FCALL                                               'var_dump'
          9        INIT_STATIC_METHOD_CALL                                  'ArrayUtils', 'containsSum'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 1220
         12        DO_FCALL                                      0  $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                                 
   40    15        INIT_FCALL                                               'var_dump'
         16        INIT_STATIC_METHOD_CALL                                  'ArrayUtils', 'containsSum'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 -7
         19        DO_FCALL                                      0  $6      
         20        SEND_VAR                                                 $6
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Class ArrayUtils:
Function containssum:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VJf7L
function name:  containsSum
number of ops:  14
compiled vars:  !0 = $data, !1 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        ASSIGN_STATIC_PROP                                       'data'
          3        OP_DATA                                                  !0
   13     4        ASSIGN_STATIC_PROP                                       'sum'
          5        OP_DATA                                                  !1
   14     6        ASSIGN_STATIC_PROP                                       'visited'
          7        OP_DATA                                                  <array>
   16     8        INIT_STATIC_METHOD_CALL                                  'found'
          9        DO_FCALL                                      0  $5      
         10        VERIFY_RETURN_TYPE                                       $5
         11      > RETURN                                                   $5
   17    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function containssum

Function found:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VJf7L
function name:  found
number of ops:  24
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   FETCH_STATIC_PROP_R          unknown             ~1      'data'
          1        BOOL_NOT                                         ~2      ~1
          2      > JMPZ                                                     ~2, ->4
   22     3    > > RETURN                                                   <false>
   25     4    >   INIT_FCALL                                               'array_pop'
          5        FETCH_STATIC_PROP_W          unknown             $3      'data'
          6        SEND_REF                                                 $3
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !0, $4
   27     9        FETCH_STATIC_PROP_R          unknown             ~7      'sum'
         10        SUB                                              ~8      ~7, !0
         11        FETCH_STATIC_PROP_IS                             ~6      'visited'
         12        ISSET_ISEMPTY_DIM_OBJ                         0          ~6, ~8
         13      > JMPZ                                                     ~9, ->15
   28    14    > > RETURN                                                   <true>
   31    15    >   FETCH_STATIC_PROP_W          unknown             $10     'visited'
         16        ASSIGN_DIM                                               $10, !0
         17        OP_DATA                                                  <true>
   33    18        INIT_STATIC_METHOD_CALL                                  'found'
         19        DO_FCALL                                      0  $12     
         20        VERIFY_RETURN_TYPE                                       $12
         21      > RETURN                                                   $12
   34    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function found

End of class ArrayUtils.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.15 ms | 1392 KiB | 21 Q