3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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
Jump found. Position 1 = -2
filename:       /in/Utl3J
function name:  (null)
number of ops:  24
compiled vars:  !0 = $workLoad, !1 = $secondPeriod
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   8     0  E >   DECLARE_CLASS                                    $2      '%00perioditerator%2Fin%2FUtl3J0x7fb74c5925e9', 'perioditerator'
         1        ADD_INTERFACE                                            $2, 'Iterator'
         2        VERIFY_ABSTRACT_CLASS                                    $2
  83     3        NEW                                              $3      :-2
         4        NEW                                              $4      :0
         5        SEND_VAL_EX                                              'Sunday+last+week'
         6        DO_FCALL                                      0          
         7        SEND_VAR_NO_REF                               0          $4
         8        NEW                                              $6      :3
         9        SEND_VAL_EX                                              'last+day+of+this+month'
        10        DO_FCALL                                      0          
        11        SEND_VAR_NO_REF                               0          $6
        12        SEND_VAL_EX                                              '1+day'
        13        DO_FCALL                                      0          
        14        ASSIGN                                                   !0, $3
  84    15        INIT_METHOD_CALL                                         !0, 'current'
        16        SEND_VAR_EX                                              !0
        17        DO_FCALL                                      0  $10     
        18        ASSIGN                                                   !1, $10
  86    19        INIT_METHOD_CALL                                         !1, 'format'
        20        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
        21        DO_FCALL                                      0  $12     
        22        ECHO                                                     $12
        23      > RETURN                                                   1

Class PeriodIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/Utl3J
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
Jump found. Position 1 = -2
filename:       /in/Utl3J
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
Jump found. Position 1 = -2
filename:       /in/Utl3J
function name:  next
number of ops:  6
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        FETCH_OBJ_FUNC_ARG                               $1      'offset'
         3        SEND_VAR_EX                                              $1
         4        DO_FCALL                                      0          
  62     5      > RETURN                                                   null

End of function next

Function key:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/Utl3J
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
Jump found. Position 1 = -2
filename:       /in/Utl3J
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
Jump found. Position 1 = -2
filename:       /in/Utl3J
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 7.1.0