3v4l.org

run code in 500+ PHP versions simultaneously
<?php class InfiniteLoggingIterator implements Iterator { public function __construct() { $this->position = 0; } public function rewind() { echo __METHOD__, PHP_EOL; $this->position = 0; } public function current() { echo __METHOD__, PHP_EOL; return $this->position; } public function key() { echo __METHOD__, PHP_EOL; return $this->position; } public function next() { echo __METHOD__, PHP_EOL; ++$this->position; } public function valid() { echo __METHOD__, PHP_EOL; return true; } } $i = new LimitIterator(new InfiniteLoggingIterator, 0, 2); echo "Rewinding outer iterator\n"; $i->rewind(); echo "\nGetting 1st value\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; echo "Proceeding to 2nd value\n"; $i->next(); echo "\nGetting 2nd (and last) value\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; echo "Proceeding to 3rd value\n"; $i->next(); echo "\nGetting 3rd value (beyond limit)\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; echo "Proceeding to 4th value!\n"; $i->next();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 68
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 68
Branch analysis from position: 66
Branch analysis from position: 68
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
Branch analysis from position: 43
filename:       /in/IrAWU
function name:  (null)
number of ops:  88
compiled vars:  !0 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                                'infiniteloggingiterator'
   34     1        NEW                                                  $1      'LimitIterator'
          2        NEW                                                  $2      'InfiniteLoggingIterator'
          3        DO_FCALL                                          0          
          4        SEND_VAR_NO_REF_EX                                           $2
          5        SEND_VAL_EX                                                  0
          6        SEND_VAL_EX                                                  2
          7        DO_FCALL                                          0          
          8        ASSIGN                                                       !0, $1
   36     9        ECHO                                                         'Rewinding+outer+iterator%0A'
   37    10        INIT_METHOD_CALL                                             !0, 'rewind'
         11        DO_FCALL                                          0          
   39    12        ECHO                                                         '%0AGetting+1st+value%0A'
   40    13        INIT_METHOD_CALL                                             !0, 'valid'
         14        DO_FCALL                                          0  $7      
         15      > JMPZ                                                         $7, ->18
         16    >   QM_ASSIGN                                            ~8      'Valid%0A'
         17      > JMP                                                          ->19
         18    >   QM_ASSIGN                                            ~8      'Not+valid%0A'
         19    >   ECHO                                                         ~8
   41    20        ECHO                                                         'Current+key%3A+'
         21        INIT_METHOD_CALL                                             !0, 'key'
         22        DO_FCALL                                          0  $9      
         23        COALESCE                                             ~10     $9
         24        QM_ASSIGN                                            ~10     'NULL'
         25        ECHO                                                         ~10
         26        ECHO                                                         '%0A'
   42    27        ECHO                                                         'Current+value%3A+'
         28        INIT_METHOD_CALL                                             !0, 'current'
         29        DO_FCALL                                          0  $11     
         30        COALESCE                                             ~12     $11
         31        QM_ASSIGN                                            ~12     'NULL'
         32        ECHO                                                         ~12
         33        ECHO                                                         '%0A'
   44    34        ECHO                                                         'Proceeding+to+2nd+value%0A'
   45    35        INIT_METHOD_CALL                                             !0, 'next'
         36        DO_FCALL                                          0          
   47    37        ECHO                                                         '%0AGetting+2nd+%28and+last%29+value%0A'
   48    38        INIT_METHOD_CALL                                             !0, 'valid'
         39        DO_FCALL                                          0  $14     
         40      > JMPZ                                                         $14, ->43
         41    >   QM_ASSIGN                                            ~15     'Valid%0A'
         42      > JMP                                                          ->44
         43    >   QM_ASSIGN                                            ~15     'Not+valid%0A'
         44    >   ECHO                                                         ~15
   49    45        ECHO                                                         'Current+key%3A+'
         46        INIT_METHOD_CALL                                             !0, 'key'
         47        DO_FCALL                                          0  $16     
         48        COALESCE                                             ~17     $16
         49        QM_ASSIGN                                            ~17     'NULL'
         50        ECHO                                                         ~17
         51        ECHO                                                         '%0A'
   50    52        ECHO                                                         'Current+value%3A+'
         53        INIT_METHOD_CALL                                             !0, 'current'
         54        DO_FCALL                                          0  $18     
         55        COALESCE                                             ~19     $18
         56        QM_ASSIGN                                            ~19     'NULL'
         57        ECHO                                                         ~19
         58        ECHO                                                         '%0A'
   52    59        ECHO                                                         'Proceeding+to+3rd+value%0A'
   53    60        INIT_METHOD_CALL                                             !0, 'next'
         61        DO_FCALL                                          0          
   55    62        ECHO                                                         '%0AGetting+3rd+value+%28beyond+limit%29%0A'
   56    63        INIT_METHOD_CALL                                             !0, 'valid'
         64        DO_FCALL                                          0  $21     
         65      > JMPZ                                                         $21, ->68
         66    >   QM_ASSIGN                                            ~22     'Valid%0A'
         67      > JMP                                                          ->69
         68    >   QM_ASSIGN                                            ~22     'Not+valid%0A'
         69    >   ECHO                                                         ~22
   57    70        ECHO                                                         'Current+key%3A+'
         71        INIT_METHOD_CALL                                             !0, 'key'
         72        DO_FCALL                                          0  $23     
         73        COALESCE                                             ~24     $23
         74        QM_ASSIGN                                            ~24     'NULL'
         75        ECHO                                                         ~24
         76        ECHO                                                         '%0A'
   58    77        ECHO                                                         'Current+value%3A+'
         78        INIT_METHOD_CALL                                             !0, 'current'
         79        DO_FCALL                                          0  $25     
         80        COALESCE                                             ~26     $25
         81        QM_ASSIGN                                            ~26     'NULL'
         82        ECHO                                                         ~26
         83        ECHO                                                         '%0A'
   60    84        ECHO                                                         'Proceeding+to+4th+value%21%0A'
   61    85        INIT_METHOD_CALL                                             !0, 'next'
         86        DO_FCALL                                          0          
         87      > RETURN                                                       1

Class InfiniteLoggingIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IrAWU
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   ASSIGN_OBJ                                                   'position'
          1        OP_DATA                                                      0
    6     2      > RETURN                                                       null

End of function __construct

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IrAWU
function name:  rewind
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   ECHO                                                         'InfiniteLoggingIterator%3A%3Arewind'
          1        ECHO                                                         '%0A'
   10     2        ASSIGN_OBJ                                                   'position'
          3        OP_DATA                                                      0
   11     4      > RETURN                                                       null

End of function rewind

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IrAWU
function name:  current
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   ECHO                                                         'InfiniteLoggingIterator%3A%3Acurrent'
          1        ECHO                                                         '%0A'
   15     2        FETCH_OBJ_R                                          ~0      'position'
          3      > RETURN                                                       ~0
   16     4*     > RETURN                                                       null

End of function current

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IrAWU
function name:  key
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   ECHO                                                         'InfiniteLoggingIterator%3A%3Akey'
          1        ECHO                                                         '%0A'
   20     2        FETCH_OBJ_R                                          ~0      'position'
          3      > RETURN                                                       ~0
   21     4*     > RETURN                                                       null

End of function key

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IrAWU
function name:  next
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   ECHO                                                         'InfiniteLoggingIterator%3A%3Anext'
          1        ECHO                                                         '%0A'
   25     2        PRE_INC_OBJ                                                  'position'
   26     3      > RETURN                                                       null

End of function next

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IrAWU
function name:  valid
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   ECHO                                                         'InfiniteLoggingIterator%3A%3Avalid'
          1        ECHO                                                         '%0A'
   30     2      > RETURN                                                       <true>
   31     3*     > RETURN                                                       null

End of function valid

End of class InfiniteLoggingIterator.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.27 ms | 2380 KiB | 13 Q