3v4l.org

run code in 500+ PHP versions simultaneously
<?php class ArraySliceIterator implements IteratorAggregate { private LimitIterator $backingIterator; public function __construct(array $array, int $offset, int $limit) { $this->backingIterator = new LimitIterator( new ArrayIterator($array), $offset, $limit ); } public function getIterator(): Traversable { return $this->backingIterator; } } function iter_search(mixed $needle, iterable $haystack, bool $strict = false): int|string|false { foreach ( $haystack as $key => $value ) { echo "$key? "; if ( ( $strict && $value === $needle ) || ( ! $strict && $value == $needle ) ) { return $key; } } echo "\nNo more items :("; return false; } $bigArray = range(0, 10_000); $key = iter_search(1066, new ArraySliceIterator($bigArray, 1_000, 100)); echo "\nResult: "; var_dump($key); echo "\n\n----\n\n"; $key = iter_search(1966, new ArraySliceIterator($bigArray, 1_000, 100)); echo "\nResult: "; var_dump($key);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HmYZV
function name:  (null)
number of ops:  36
compiled vars:  !0 = $bigArray, !1 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                                'arraysliceiterator'
   36     1        INIT_FCALL                                                   'range'
          2        SEND_VAL                                                     0
          3        SEND_VAL                                                     10000
          4        DO_ICALL                                             $2      
          5        ASSIGN                                                       !0, $2
   38     6        INIT_FCALL                                                   'iter_search'
          7        SEND_VAL                                                     1066
          8        NEW                                                  $4      'ArraySliceIterator'
          9        SEND_VAR_EX                                                  !0
         10        SEND_VAL_EX                                                  1000
         11        SEND_VAL_EX                                                  100
         12        DO_FCALL                                          0          
         13        SEND_VAR                                                     $4
         14        DO_FCALL                                          0  $6      
         15        ASSIGN                                                       !1, $6
   39    16        ECHO                                                         '%0AResult%3A+'
         17        INIT_FCALL                                                   'var_dump'
         18        SEND_VAR                                                     !1
         19        DO_ICALL                                                     
   41    20        ECHO                                                         '%0A%0A----%0A%0A'
   43    21        INIT_FCALL                                                   'iter_search'
         22        SEND_VAL                                                     1966
         23        NEW                                                  $9      'ArraySliceIterator'
         24        SEND_VAR_EX                                                  !0
         25        SEND_VAL_EX                                                  1000
         26        SEND_VAL_EX                                                  100
         27        DO_FCALL                                          0          
         28        SEND_VAR                                                     $9
         29        DO_FCALL                                          0  $11     
         30        ASSIGN                                                       !1, $11
   44    31        ECHO                                                         '%0AResult%3A+'
         32        INIT_FCALL                                                   'var_dump'
         33        SEND_VAR                                                     !1
         34        DO_ICALL                                                     
         35      > RETURN                                                       1

Function iter_search:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
Branch analysis from position: 18
Branch analysis from position: 12
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/HmYZV
function name:  iter_search
number of ops:  28
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $strict, !3 = $value, !4 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      <false>
   22     3      > FE_RESET_R                                           $5      !1, ->23
          4    > > FE_FETCH_R                                           ~6      $5, !3, ->23
          5    >   ASSIGN                                                       !4, ~6
   23     6        NOP                                                          
          7        FAST_CONCAT                                          ~8      !4, '%3F+'
          8        ECHO                                                         ~8
   25     9      > JMPZ_EX                                              ~9      !2, ->12
         10    >   IS_IDENTICAL                                         ~10     !3, !0
         11        BOOL                                                 ~9      ~10
         12    > > JMPNZ_EX                                             ~9      ~9, ->18
   27    13    >   BOOL_NOT                                             ~11     !2
         14      > JMPZ_EX                                              ~11     ~11, ->17
         15    >   IS_EQUAL                                             ~12     !3, !0
         16        BOOL                                                 ~11     ~12
         17    >   BOOL                                                 ~9      ~11
         18    > > JMPZ                                                         ~9, ->22
   29    19    >   VERIFY_RETURN_TYPE                                           !4
         20        FE_FREE                                                      $5
         21      > RETURN                                                       !4
   22    22    > > JMP                                                          ->4
         23    >   FE_FREE                                                      $5
   32    24        ECHO                                                         '%0ANo+more+items+%3A%28'
   33    25      > RETURN                                                       <false>
   34    26*       VERIFY_RETURN_TYPE                                           
         27*     > RETURN                                                       null

End of function iter_search

Class ArraySliceIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HmYZV
function name:  __construct
number of ops:  14
compiled vars:  !0 = $array, !1 = $offset, !2 = $limit
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    7     3        NEW                                                  $4      'LimitIterator'
    8     4        NEW                                                  $5      'ArrayIterator'
          5        SEND_VAR_EX                                                  !0
          6        DO_FCALL                                          0          
          7        SEND_VAR_NO_REF_EX                                           $5
          8        SEND_VAR_EX                                                  !1
          9        SEND_VAR_EX                                                  !2
    7    10        DO_FCALL                                          0          
         11        ASSIGN_OBJ                                                   'backingIterator'
    8    12        OP_DATA                                                      $4
   12    13      > RETURN                                                       null

End of function __construct

Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HmYZV
function name:  getIterator
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   FETCH_OBJ_R                                          ~0      'backingIterator'
          1        VERIFY_RETURN_TYPE                                           ~0
          2      > RETURN                                                       ~0
   17     3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function getiterator

End of class ArraySliceIterator.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.37 ms | 1509 KiB | 17 Q