3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DateIterator implements \Iterator { const FORWARD = 'fwd'; const BACKWARD = 'bwd'; /** * @var \DateTime */ private $from; /** * @var \DateTime */ private $to; /** * @var \DateTime */ private $current; /** * @var \DateInterval */ private $interval; /** * @var string */ private $direction = self::FORWARD; public function __construct(\DateTime $from, \DateTime $to, \DateInterval $interval = null) { $this->from = $from; $this->to = $to; if ($interval === null) { $interval = new \DateInterval('P1D'); } $this->interval = $interval; if ($to < $from) { $this->direction = self::BACKWARD; } else { $this->direction = self::FORWARD; } $this->rewind(); } /** * Return the current element * * @link http://php.net/manual/en/iterator.current.php * @return mixed Can return any type. * @since 5.0.0 */ public function current() { return $this->current; } /** * Move forward to next element * * @link http://php.net/manual/en/iterator.next.php * @return void Any returned value is ignored. * @since 5.0.0 */ public function next() { if ($this->direction === self::FORWARD) { $this->current = $this->current->add($this->interval); } else { $this->current = $this->current->sub($this->interval); } } /** * Return the key of the current element * * @link http://php.net/manual/en/iterator.key.php * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ public function key() { return null; } /** * Checks if current position is valid * * @link http://php.net/manual/en/iterator.valid.php * @return boolean The return value will be casted to boolean and then evaluated. * Returns true on success or false on failure. * @since 5.0.0 */ public function valid() { if ($this->direction === self::FORWARD) { return $this->current < $this->to; } else { return $this->current > $this->from; } } /** * Rewind the Iterator to the first element * * @link http://php.net/manual/en/iterator.rewind.php * @return void Any returned value is ignored. * @since 5.0.0 */ public function rewind() { $this->current = $this->from; } } $from = new \DateTime(); $to = new \DateTime('+1 month'); $i = new DateIterator($from, $to); foreach ($i as $x) { echo $x->format('Y-m-d'), PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/DlGB0
function name:  (null)
number of ops:  23
compiled vars:  !0 = $from, !1 = $to, !2 = $i, !3 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'dateiterator'
  124     1        NEW                                              $4      'DateTime'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $4
  125     4        NEW                                              $7      'DateTime'
          5        SEND_VAL_EX                                              '%2B1+month'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $7
  127     8        NEW                                              $10     'DateIterator'
          9        SEND_VAR_EX                                              !0
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $10
  129    13      > FE_RESET_R                                       $13     !2, ->21
         14    > > FE_FETCH_R                                               $13, !3, ->21
  130    15    >   INIT_METHOD_CALL                                         !3, 'format'
         16        SEND_VAL_EX                                              'Y-m-d'
         17        DO_FCALL                                      0  $14     
         18        ECHO                                                     $14
         19        ECHO                                                     '%0A'
  129    20      > JMP                                                      ->14
         21    >   FE_FREE                                                  $13
  131    22      > RETURN                                                   1

Class DateIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/DlGB0
function name:  __construct
number of ops:  25
compiled vars:  !0 = $from, !1 = $to, !2 = $interval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   36     3        ASSIGN_OBJ                                               'from'
          4        OP_DATA                                                  !0
   37     5        ASSIGN_OBJ                                               'to'
          6        OP_DATA                                                  !1
   39     7        TYPE_CHECK                                    2          !2
          8      > JMPZ                                                     ~5, ->13
   40     9    >   NEW                                              $6      'DateInterval'
         10        SEND_VAL_EX                                              'P1D'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $6
   43    13    >   ASSIGN_OBJ                                               'interval'
         14        OP_DATA                                                  !2
   45    15        IS_SMALLER                                               !1, !0
         16      > JMPZ                                                     ~10, ->20
   46    17    >   ASSIGN_OBJ                                               'direction'
         18        OP_DATA                                                  'bwd'
         19      > JMP                                                      ->22
   48    20    >   ASSIGN_OBJ                                               'direction'
         21        OP_DATA                                                  'fwd'
   51    22    >   INIT_METHOD_CALL                                         'rewind'
         23        DO_FCALL                                      0          
   52    24      > RETURN                                                   null

End of function __construct

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

End of function current

Function next:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DlGB0
function name:  next
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   FETCH_OBJ_R                                      ~0      'direction'
          1        IS_IDENTICAL                                             ~0, 'fwd'
          2      > JMPZ                                                     ~1, ->12
   76     3    >   FETCH_OBJ_R                                      ~3      'current'
          4        INIT_METHOD_CALL                                         ~3, 'add'
          5        CHECK_FUNC_ARG                                           
          6        FETCH_OBJ_FUNC_ARG                               $4      'interval'
          7        SEND_FUNC_ARG                                            $4
          8        DO_FCALL                                      0  $5      
          9        ASSIGN_OBJ                                               'current'
         10        OP_DATA                                                  $5
         11      > JMP                                                      ->20
   78    12    >   FETCH_OBJ_R                                      ~7      'current'
         13        INIT_METHOD_CALL                                         ~7, 'sub'
         14        CHECK_FUNC_ARG                                           
         15        FETCH_OBJ_FUNC_ARG                               $8      'interval'
         16        SEND_FUNC_ARG                                            $8
         17        DO_FCALL                                      0  $9      
         18        ASSIGN_OBJ                                               'current'
         19        OP_DATA                                                  $9
   80    20    > > 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/DlGB0
function name:  key
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E > > RETURN                                                   null
   92     1*     > RETURN                                                   null

End of function key

Function valid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DlGB0
function name:  valid
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  104     0  E >   FETCH_OBJ_R                                      ~0      'direction'
          1        IS_IDENTICAL                                             ~0, 'fwd'
          2      > JMPZ                                                     ~1, ->8
  105     3    >   FETCH_OBJ_R                                      ~2      'current'
          4        FETCH_OBJ_R                                      ~3      'to'
          5        IS_SMALLER                                       ~4      ~2, ~3
          6      > RETURN                                                   ~4
          7*       JMP                                                      ->12
  107     8    >   FETCH_OBJ_R                                      ~5      'current'
          9        FETCH_OBJ_R                                      ~6      'from'
         10        IS_SMALLER                                       ~7      ~6, ~5
         11      > RETURN                                                   ~7
  109    12*     > 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/DlGB0
function name:  rewind
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  120     0  E >   FETCH_OBJ_R                                      ~1      'from'
          1        ASSIGN_OBJ                                               'current'
          2        OP_DATA                                                  ~1
  121     3      > RETURN                                                   null

End of function rewind

End of class DateIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.16 ms | 1403 KiB | 13 Q