3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Class PeriodIterator * * @author Efimov Evgeniy <evgeniy.efimov@alpari.org> */ class PeriodIterator implements \Iterator { /** * Start date * * @var \DateTime */ private $startDate; /** * End date * * @var \DateTime */ private $endDate; /** * Iteration offset * * @var string */ private $offset; /** * Current iteration date * * @var \DateTime */ private $currentDate; /** * PeriodIterator constructor. * * @param \DateTime $startDate Start date * @param \DateTime $endDate End date * @param string $offset Offset for iteration */ public function __construct(\DateTime $startDate, \DateTime $endDate, $offset) { $this->startDate = $startDate; $this->endDate = $endDate; $this->offset = $offset; } /** {@inheritdoc} */ public function current() { return $this->currentDate; } /** {@inheritdoc} */ public function next() { $this->currentDate->modify($this->offset); } /** {@inheritdoc} */ public function key() { return $this->currentDate->getTimestamp(); } /** {@inheritdoc} */ public function valid() { return $this->currentDate->getTimestamp() <= $this->endDate->getTimestamp(); } /** {@inheritdoc} */ public function rewind() { $this->currentDate = clone $this->startDate; } } $workLoad = new PeriodIterator(new \DateTime('sunday last week'), new DateTime('last day of this month'), "1 day" ); $secondPeriod = $workLoad->current($workLoad); echo $secondPeriod->format('Y-m-d H:i:s');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YvOku
function name:  (null)
number of ops:  22
compiled vars:  !0 = $workLoad, !1 = $secondPeriod
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'perioditerator'
   83     1        NEW                                              $2      'PeriodIterator'
          2        NEW                                              $3      'DateTime'
          3        SEND_VAL_EX                                              'sunday+last+week'
          4        DO_FCALL                                      0          
          5        SEND_VAR_NO_REF_EX                                       $3
          6        NEW                                              $5      'DateTime'
          7        SEND_VAL_EX                                              'last+day+of+this+month'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $5
         10        SEND_VAL_EX                                              '1+day'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !0, $2
   84    13        INIT_METHOD_CALL                                         !0, 'current'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0  $9      
         16        ASSIGN                                                   !1, $9
   86    17        INIT_METHOD_CALL                                         !1, 'format'
         18        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         19        DO_FCALL                                      0  $11     
         20        ECHO                                                     $11
         21      > RETURN                                                   1

Class PeriodIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YvOku
function name:  __construct
number of ops:  10
compiled vars:  !0 = $startDate, !1 = $endDate, !2 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   47     3        ASSIGN_OBJ                                               'startDate'
          4        OP_DATA                                                  !0
   48     5        ASSIGN_OBJ                                               'endDate'
          6        OP_DATA                                                  !1
   49     7        ASSIGN_OBJ                                               'offset'
          8        OP_DATA                                                  !2
   50     9      > 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/YvOku
function name:  current
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'currentDate'
          1      > RETURN                                                   ~0
   56     2*     > 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/YvOku
function name:  next
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   FETCH_OBJ_R                                      ~0      'currentDate'
          1        INIT_METHOD_CALL                                         ~0, 'modify'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'offset'
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0          
   62     6      > 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/YvOku
function name:  key
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   FETCH_OBJ_R                                      ~0      'currentDate'
          1        INIT_METHOD_CALL                                         ~0, 'getTimestamp'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   68     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/YvOku
function name:  valid
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   FETCH_OBJ_R                                      ~0      'currentDate'
          1        INIT_METHOD_CALL                                         ~0, 'getTimestamp'
          2        DO_FCALL                                      0  $1      
          3        FETCH_OBJ_R                                      ~2      'endDate'
          4        INIT_METHOD_CALL                                         ~2, 'getTimestamp'
          5        DO_FCALL                                      0  $3      
          6        IS_SMALLER_OR_EQUAL                              ~4      $1, $3
          7      > RETURN                                                   ~4
   74     8*     > 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/YvOku
function name:  rewind
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   FETCH_OBJ_R                                      ~1      'startDate'
          1        CLONE                                            ~2      ~1
          2        ASSIGN_OBJ                                               'currentDate'
          3        OP_DATA                                                  ~2
   80     4      > RETURN                                                   null

End of function rewind

End of class PeriodIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.25 ms | 1390 KiB | 13 Q