3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Entry { private $modifier; private $startDateTime; private $untilDateTime; public function __construct($modifier, DateTime $startDateTime, DateTime $untilDateTime = null) { $this->setModifier($modifier); $this->setStartDateTime($startDateTime); if ($untilDateTime != null) { $this->setUntilDateTime($untilDateTime); } } public function setModifier($modifier) { $this->modifier = (string) $modifier; } public function getModifier() { return $this->modifier; } public function setStartDateTime(DateTime $startDateTime) { $this->startDateTime = $startDateTime; } public function getStartDateTime() { return clone $this->startDateTime; } public function setUntilDateTime(DateTime $untilDateTime) { $this->untilDateTime = $untilDateTime; } public function hasUntilDateTime() { return $this->untilDateTime instanceof DateTime; } public function getUntilDateTime() { return clone $this->untilDateTime; } public function match(DateTime $matchDateTime) { $currentDateTime = $this->getStartDateTime(); while ($currentDateTime <= $matchDateTime) { if ($currentDateTime->diff($matchDateTime)->days === 0) { return true; } if ($this->hasUntilDateTime() && $this->getUntilDateTime() < $currentDateTime) { break; } $currentDateTime->modify($this->getModifier()); } return false; } } date_default_timezone_set('America/Toronto'); $untilDateTime = new DateTime('2014-01-01'); $entries = [ new Entry('+1 month', new DateTime('2013-01-01')), new Entry('+2 week', new DateTime('2013-01-01')), new Entry('+3 day', new DateTime('2013-01-01')), ]; $todayDateTime = new DateTime('2013-01-01'); while ($todayDateTime < $untilDateTime) { var_dump($todayDateTime->format('Y-m-d')); foreach ($entries as $entry) { if ($entry->match($todayDateTime)) { var_dump($entry->getModifier()); } } $todayDateTime->modify('+1 day'); echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 37
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 55
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 55
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 54
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 37
Branch analysis from position: 62
Branch analysis from position: 37
Branch analysis from position: 55
filename:       /in/TI4tN
function name:  (null)
number of ops:  63
compiled vars:  !0 = $untilDateTime, !1 = $entries, !2 = $todayDateTime, !3 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   INIT_FCALL                                               'date_default_timezone_set'
          1        SEND_VAL                                                 'America%2FToronto'
          2        DO_ICALL                                                 
   63     3        NEW                                              $5      'DateTime'
          4        SEND_VAL_EX                                              '2014-01-01'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $5
   66     7        NEW                                              $8      'Entry'
          8        SEND_VAL_EX                                              '%2B1+month'
          9        NEW                                              $9      'DateTime'
         10        SEND_VAL_EX                                              '2013-01-01'
         11        DO_FCALL                                      0          
         12        SEND_VAR_NO_REF_EX                                       $9
         13        DO_FCALL                                      0          
         14        INIT_ARRAY                                       ~12     $8
   67    15        NEW                                              $13     'Entry'
         16        SEND_VAL_EX                                              '%2B2+week'
         17        NEW                                              $14     'DateTime'
         18        SEND_VAL_EX                                              '2013-01-01'
         19        DO_FCALL                                      0          
         20        SEND_VAR_NO_REF_EX                                       $14
         21        DO_FCALL                                      0          
         22        ADD_ARRAY_ELEMENT                                ~12     $13
   68    23        NEW                                              $17     'Entry'
         24        SEND_VAL_EX                                              '%2B3+day'
         25        NEW                                              $18     'DateTime'
         26        SEND_VAL_EX                                              '2013-01-01'
         27        DO_FCALL                                      0          
         28        SEND_VAR_NO_REF_EX                                       $18
         29        DO_FCALL                                      0          
         30        ADD_ARRAY_ELEMENT                                ~12     $17
   65    31        ASSIGN                                                   !1, ~12
   71    32        NEW                                              $22     'DateTime'
         33        SEND_VAL_EX                                              '2013-01-01'
         34        DO_FCALL                                      0          
         35        ASSIGN                                                   !2, $22
   72    36      > JMP                                                      ->60
   73    37    >   INIT_FCALL                                               'var_dump'
         38        INIT_METHOD_CALL                                         !2, 'format'
         39        SEND_VAL_EX                                              'Y-m-d'
         40        DO_FCALL                                      0  $25     
         41        SEND_VAR                                                 $25
         42        DO_ICALL                                                 
   74    43      > FE_RESET_R                                       $27     !1, ->55
         44    > > FE_FETCH_R                                               $27, !3, ->55
   75    45    >   INIT_METHOD_CALL                                         !3, 'match'
         46        SEND_VAR_EX                                              !2
         47        DO_FCALL                                      0  $28     
         48      > JMPZ                                                     $28, ->54
   76    49    >   INIT_FCALL                                               'var_dump'
         50        INIT_METHOD_CALL                                         !3, 'getModifier'
         51        DO_FCALL                                      0  $29     
         52        SEND_VAR                                                 $29
         53        DO_ICALL                                                 
   74    54    > > JMP                                                      ->44
         55    >   FE_FREE                                                  $27
   79    56        INIT_METHOD_CALL                                         !2, 'modify'
         57        SEND_VAL_EX                                              '%2B1+day'
         58        DO_FCALL                                      0          
   80    59        ECHO                                                     '%0A'
   72    60    >   IS_SMALLER                                               !2, !0
         61      > JMPNZ                                                    ~32, ->37
   81    62    > > RETURN                                                   1

Class Entry:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/TI4tN
function name:  __construct
number of ops:  15
compiled vars:  !0 = $modifier, !1 = $startDateTime, !2 = $untilDateTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   10     3        INIT_METHOD_CALL                                         'setModifier'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
   11     6        INIT_METHOD_CALL                                         'setStartDateTime'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
   12     9        IS_NOT_EQUAL                                             !2, null
         10      > JMPZ                                                     ~5, ->14
   13    11    >   INIT_METHOD_CALL                                         'setUntilDateTime'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0          
   15    14    > > RETURN                                                   null

End of function __construct

Function setmodifier:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TI4tN
function name:  setModifier
number of ops:  5
compiled vars:  !0 = $modifier
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        CAST                                          6  ~2      !0
          2        ASSIGN_OBJ                                               'modifier'
          3        OP_DATA                                                  ~2
   19     4      > RETURN                                                   null

End of function setmodifier

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

End of function getmodifier

Function setstartdatetime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TI4tN
function name:  setStartDateTime
number of ops:  4
compiled vars:  !0 = $startDateTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        ASSIGN_OBJ                                               'startDateTime'
          2        OP_DATA                                                  !0
   27     3      > RETURN                                                   null

End of function setstartdatetime

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

End of function getstartdatetime

Function setuntildatetime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TI4tN
function name:  setUntilDateTime
number of ops:  4
compiled vars:  !0 = $untilDateTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        ASSIGN_OBJ                                               'untilDateTime'
          2        OP_DATA                                                  !0
   35     3      > RETURN                                                   null

End of function setuntildatetime

Function hasuntildatetime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TI4tN
function name:  hasUntilDateTime
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   FETCH_OBJ_R                                      ~0      'untilDateTime'
          1        INSTANCEOF                                       ~1      ~0, 'DateTime'
          2      > RETURN                                                   ~1
   39     3*     > RETURN                                                   null

End of function hasuntildatetime

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

End of function getuntildatetime

Function match:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 5
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 5
Branch analysis from position: 28
Branch analysis from position: 5
Branch analysis from position: 19
filename:       /in/TI4tN
function name:  match
number of ops:  30
compiled vars:  !0 = $matchDateTime, !1 = $currentDateTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   46     1        INIT_METHOD_CALL                                         'getStartDateTime'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !1, $2
   47     4      > JMP                                                      ->26
   48     5    >   INIT_METHOD_CALL                                         !1, 'diff'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $4      
          8        FETCH_OBJ_R                                      ~5      $4, 'days'
          9        IS_IDENTICAL                                             ~5, 0
         10      > JMPZ                                                     ~6, ->12
   49    11    > > RETURN                                                   <true>
   51    12    >   INIT_METHOD_CALL                                         'hasUntilDateTime'
         13        DO_FCALL                                      0  $7      
         14      > JMPZ_EX                                          ~8      $7, ->19
         15    >   INIT_METHOD_CALL                                         'getUntilDateTime'
         16        DO_FCALL                                      0  $9      
         17        IS_SMALLER                                       ~10     $9, !1
         18        BOOL                                             ~8      ~10
         19    > > JMPZ                                                     ~8, ->21
   52    20    > > JMP                                                      ->28
   54    21    >   INIT_METHOD_CALL                                         !1, 'modify'
         22        INIT_METHOD_CALL                                         'getModifier'
         23        DO_FCALL                                      0  $11     
         24        SEND_VAR_NO_REF_EX                                       $11
         25        DO_FCALL                                      0          
   47    26    >   IS_SMALLER_OR_EQUAL                                      !1, !0
         27      > JMPNZ                                                    ~13, ->5
   56    28    > > RETURN                                                   <false>
   57    29*     > RETURN                                                   null

End of function match

End of class Entry.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.88 ms | 1412 KiB | 17 Q