3v4l.org

run code in 500+ PHP versions simultaneously
<?php class BeforeAfterIterator implements Iterator { private $iterator; public function __construct(iterable $iterator, $before, $after) { if (!$iterator instanceof Iterator) { $iterator = (function ($iterable) { yield from $iterable; })($iterator); } if ($iterator->valid()) { $this->iterator = new AppendIterator(); $this->iterator->append(new ArrayIterator([$before])); $this->iterator->append($iterator); $this->iterator->append(new ArrayIterator([$after])); } else { $this->iterator = new ArrayIterator([]); } } public function current() { return $this->iterator->current(); } public function next() { $this->iterator->next(); } public function key() { return $this->iterator->key(); } public function valid() { return $this->iterator->valid(); } public function rewind() { $this->iterator->rewind(); } } $begin = new DateTime('2020-02-01'); $end = new DateTime('2020-02-29'); $interval = new DateInterval('P1D'); $daterange = new DatePeriod($begin, $interval ,$end); foreach (new BeforeAfterIterator($daterange, new \DateTime('2020-01-31'), new \DateTime('2020-03-01')) as $value) { echo $value->format('Y-m-d'), PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 38
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 38
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/kkfgL
function name:  (null)
number of ops:  40
compiled vars:  !0 = $begin, !1 = $end, !2 = $interval, !3 = $daterange, !4 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                                'beforeafteriterator'
   50     1        NEW                                                  $5      'DateTime'
          2        SEND_VAL_EX                                                  '2020-02-01'
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !0, $5
   51     5        NEW                                                  $8      'DateTime'
          6        SEND_VAL_EX                                                  '2020-02-29'
          7        DO_FCALL                                          0          
          8        ASSIGN                                                       !1, $8
   53     9        NEW                                                  $11     'DateInterval'
         10        SEND_VAL_EX                                                  'P1D'
         11        DO_FCALL                                          0          
         12        ASSIGN                                                       !2, $11
   54    13        NEW                                                  $14     'DatePeriod'
         14        SEND_VAR_EX                                                  !0
         15        SEND_VAR_EX                                                  !2
         16        SEND_VAR_EX                                                  !1
         17        DO_FCALL                                          0          
         18        ASSIGN                                                       !3, $14
   56    19        NEW                                                  $17     'BeforeAfterIterator'
         20        SEND_VAR_EX                                                  !3
         21        NEW                                                  $18     'DateTime'
         22        SEND_VAL_EX                                                  '2020-01-31'
         23        DO_FCALL                                          0          
         24        SEND_VAR_NO_REF_EX                                           $18
         25        NEW                                                  $20     'DateTime'
         26        SEND_VAL_EX                                                  '2020-03-01'
         27        DO_FCALL                                          0          
         28        SEND_VAR_NO_REF_EX                                           $20
         29        DO_FCALL                                          0          
         30      > FE_RESET_R                                           $23     $17, ->38
         31    > > FE_FETCH_R                                                   $23, !4, ->38
   57    32    >   INIT_METHOD_CALL                                             !4, 'format'
         33        SEND_VAL_EX                                                  'Y-m-d'
         34        DO_FCALL                                          0  $24     
         35        ECHO                                                         $24
         36        ECHO                                                         '%0A'
   56    37      > JMP                                                          ->31
         38    >   FE_FREE                                                      $23
   58    39      > RETURN                                                       1

Class BeforeAfterIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 39
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/kkfgL
function name:  __construct
number of ops:  45
compiled vars:  !0 = $iterator, !1 = $before, !2 = $after
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    8     3        INSTANCEOF                                           ~3      !0, 'Iterator'
          4        BOOL_NOT                                             ~4      ~3
          5      > JMPZ                                                         ~4, ->11
    9     6    >   DECLARE_LAMBDA_FUNCTION                              ~5      [0]
   11     7        INIT_DYNAMIC_CALL                                            ~5
          8        SEND_VAR_EX                                                  !0
          9        DO_FCALL                                          0  $6      
    9    10        ASSIGN                                                       !0, $6
   14    11    >   INIT_METHOD_CALL                                             !0, 'valid'
         12        DO_FCALL                                          0  $8      
         13      > JMPZ                                                         $8, ->39
   15    14    >   NEW                                                  $10     'AppendIterator'
         15        DO_FCALL                                          0          
         16        ASSIGN_OBJ                                                   'iterator'
         17        OP_DATA                                                      $10
   16    18        FETCH_OBJ_R                                          ~12     'iterator'
         19        INIT_METHOD_CALL                                             ~12, 'append'
         20        NEW                                                  $13     'ArrayIterator'
         21        INIT_ARRAY                                           ~14     !1
         22        SEND_VAL_EX                                                  ~14
         23        DO_FCALL                                          0          
         24        SEND_VAR_NO_REF_EX                                           $13
         25        DO_FCALL                                          0          
   17    26        FETCH_OBJ_R                                          ~17     'iterator'
         27        INIT_METHOD_CALL                                             ~17, 'append'
         28        SEND_VAR_EX                                                  !0
         29        DO_FCALL                                          0          
   18    30        FETCH_OBJ_R                                          ~19     'iterator'
         31        INIT_METHOD_CALL                                             ~19, 'append'
         32        NEW                                                  $20     'ArrayIterator'
         33        INIT_ARRAY                                           ~21     !2
         34        SEND_VAL_EX                                                  ~21
         35        DO_FCALL                                          0          
         36        SEND_VAR_NO_REF_EX                                           $20
         37        DO_FCALL                                          0          
   14    38      > JMP                                                          ->44
   20    39    >   NEW                                                  $25     'ArrayIterator'
         40        SEND_VAL_EX                                                  <array>
         41        DO_FCALL                                          0          
         42        ASSIGN_OBJ                                                   'iterator'
         43        OP_DATA                                                      $25
   22    44    > > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/kkfgL
function name:  {closure:BeforeAfterIterator::__construct():9}
number of ops:  5
compiled vars:  !0 = $iterable
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
          1        GENERATOR_CREATE                                             
   10     2        YIELD_FROM                                           ~1      !0
          3        FREE                                                         ~1
   11     4      > GENERATOR_RETURN                                             

End of Dynamic Function 0

End of function __construct

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kkfgL
function name:  current
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   FETCH_OBJ_R                                          ~0      'iterator'
          1        INIT_METHOD_CALL                                             ~0, 'current'
          2        DO_FCALL                                          0  $1      
          3      > RETURN                                                       $1
   27     4*     > RETURN                                                       null

End of function current

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kkfgL
function name:  next
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   FETCH_OBJ_R                                          ~0      'iterator'
          1        INIT_METHOD_CALL                                             ~0, 'next'
          2        DO_FCALL                                          0          
   32     3      > RETURN                                                       null

End of function next

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kkfgL
function name:  key
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   36     0  E >   FETCH_OBJ_R                                          ~0      'iterator'
          1        INIT_METHOD_CALL                                             ~0, 'key'
          2        DO_FCALL                                          0  $1      
          3      > RETURN                                                       $1
   37     4*     > RETURN                                                       null

End of function key

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kkfgL
function name:  valid
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   41     0  E >   FETCH_OBJ_R                                          ~0      'iterator'
          1        INIT_METHOD_CALL                                             ~0, 'valid'
          2        DO_FCALL                                          0  $1      
          3      > RETURN                                                       $1
   42     4*     > RETURN                                                       null

End of function valid

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kkfgL
function name:  rewind
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E >   FETCH_OBJ_R                                          ~0      'iterator'
          1        INIT_METHOD_CALL                                             ~0, 'rewind'
          2        DO_FCALL                                          0          
   47     3      > RETURN                                                       null

End of function rewind

End of class BeforeAfterIterator.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
176.08 ms | 2321 KiB | 13 Q