3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Workaround for date period iteration under php 5.2 * * @author pgorbach <pgorbach@goodgamestudios.com> * @package publishers * @version $Id$ */ class GgsDatePeriod implements Iterator { /** * @var \DateTime */ protected $current; /** * @var \DateTime */ protected $start; /** * @var \DateTime */ protected $end; /** * @var string */ protected $interval; /** * @todo replace this class by build in php class DatePeriod * * @param \DateTime $start * @param string $interval * @param \DateTime $end * @param int $options */ public function __construct($start, $interval, $end, $options = 0) { $this->start = $start; $this->end = $end; $this->interval = $interval; $this->current = clone($start); } /** * (PHP 5 &gt;= 5.0.0)<br/> * Return the current element * * @link http://php.net/manual/en/iterator.current.php * @return mixed Can return any type. */ public function current() { return $this->current; } /** * (PHP 5 &gt;= 5.0.0)<br/> * Move forward to next element * * @link http://php.net/manual/en/iterator.next.php * @return void Any returned value is ignored. */ public function next() { $this->current->modify($this->interval); } /** * (PHP 5 &gt;= 5.0.0)<br/> * 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. */ public function key() { return strtotime($this->current()->format('Y-m-d')); } /** * (PHP 5 &gt;= 5.0.0)<br/> * 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. */ public function valid() { return $this->current() <= $this->end; } /** * (PHP 5 &gt;= 5.0.0)<br/> * Rewind the Iterator to the first element * * @link http://php.net/manual/en/iterator.rewind.php * @return void Any returned value is ignored. */ public function rewind() { $this->current = clone($this->start); } } $startDateTime = new Date('2010-01-01'); $endDateTime = new Date('2010-08-01'); $period = new GgsDatePeriod($startDateTime, 86400, $endDateTime); foreach ($period as $iterDate) { echo $iterDate->format('Y-m-d'); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/QtUlS
function name:  (null)
number of ops:  24
compiled vars:  !0 = $startDateTime, !1 = $endDateTime, !2 = $period, !3 = $iterDate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'ggsdateperiod'
  107     1        NEW                                              $4      'Date'
          2        SEND_VAL_EX                                              '2010-01-01'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $4
  108     5        NEW                                              $7      'Date'
          6        SEND_VAL_EX                                              '2010-08-01'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $7
  110     9        NEW                                              $10     'GgsDatePeriod'
         10        SEND_VAR_EX                                              !0
         11        SEND_VAL_EX                                              86400
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !2, $10
  112    15      > FE_RESET_R                                       $13     !2, ->22
         16    > > FE_FETCH_R                                               $13, !3, ->22
  113    17    >   INIT_METHOD_CALL                                         !3, 'format'
         18        SEND_VAL_EX                                              'Y-m-d'
         19        DO_FCALL                                      0  $14     
         20        ECHO                                                     $14
  112    21      > JMP                                                      ->16
         22    >   FE_FREE                                                  $13
  114    23      > RETURN                                                   1

Class GgsDatePeriod:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QtUlS
function name:  __construct
number of ops:  14
compiled vars:  !0 = $start, !1 = $interval, !2 = $end, !3 = $options
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      0
   39     4        ASSIGN_OBJ                                               'start'
          5        OP_DATA                                                  !0
   40     6        ASSIGN_OBJ                                               'end'
          7        OP_DATA                                                  !2
   41     8        ASSIGN_OBJ                                               'interval'
          9        OP_DATA                                                  !1
   42    10        CLONE                                            ~8      !0
         11        ASSIGN_OBJ                                               'current'
         12        OP_DATA                                                  ~8
   43    13      > 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/QtUlS
function name:  current
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1      > RETURN                                                   ~0
   55     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/QtUlS
function name:  next
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1        INIT_METHOD_CALL                                         ~0, 'modify'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'interval'
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0          
   67     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/QtUlS
function name:  key
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   INIT_FCALL                                               'strtotime'
          1        INIT_METHOD_CALL                                         'current'
          2        DO_FCALL                                      0  $0      
          3        INIT_METHOD_CALL                                         $0, 'format'
          4        SEND_VAL_EX                                              'Y-m-d'
          5        DO_FCALL                                      0  $1      
          6        SEND_VAR                                                 $1
          7        DO_ICALL                                         $2      
          8      > RETURN                                                   $2
   79     9*     > 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/QtUlS
function name:  valid
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   INIT_METHOD_CALL                                         'current'
          1        DO_FCALL                                      0  $0      
          2        FETCH_OBJ_R                                      ~1      'end'
          3        IS_SMALLER_OR_EQUAL                              ~2      $0, ~1
          4      > RETURN                                                   ~2
   92     5*     > 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/QtUlS
function name:  rewind
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  103     0  E >   FETCH_OBJ_R                                      ~1      'start'
          1        CLONE                                            ~2      ~1
          2        ASSIGN_OBJ                                               'current'
          3        OP_DATA                                                  ~2
  104     4      > RETURN                                                   null

End of function rewind

End of class GgsDatePeriod.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.62 ms | 1404 KiB | 15 Q