1--TEST-- 2Test DatePeriod::__serialize and DatePeriod::__unserialize (start/recurrences) 3--FILE-- 4<?php 5date_default_timezone_set("Europe/London"); 6 7$s = new DateTimeImmutable("1978-12-22 09:15:00 Europe/Amsterdam"); 8$i = DateInterval::createFromDateString('first monday of next month'); 9$p = new DatePeriod($s, $i, 7, DatePeriod::EXCLUDE_START_DATE); 10echo "Original object:\n"; 11var_dump($p); 12 13echo "\n\nIterate of object:\n"; 14foreach ( $p as $d ) 15{ 16 echo $d->format(DateTime::ISO8601), "\n"; 17} 18 19echo "\n\nSerialised object:\n"; 20$s = serialize($p); 21var_dump($s); 22 23echo "\n\nUnserialised object:\n"; 24$e = unserialize($s); 25var_dump($e); 26 27echo "\n\nCalling __serialize manually:\n"; 28var_dump($p->__serialize()); 29 30echo "\n\nIterate of unserialised object:\n"; 31foreach ( $p as $d ) 32{ 33 echo $d->format(DateTime::ISO8601), "\n"; 34} 35?> 36--EXPECTF-- 37Original object: 38object(DatePeriod)#%d (%d) { 39 ["start"]=> 40 object(DateTimeImmutable)#%d (%d) { 41 ["date"]=> 42 string(26) "1978-12-22 09:15:00.000000" 43 ["timezone_type"]=> 44 int(3) 45 ["timezone"]=> 46 string(16) "Europe/Amsterdam" 47 } 48 ["current"]=> 49 NULL 50 ["end"]=> 51 NULL 52 ["interval"]=> 53 object(DateInterval)#%d (%d) { 54 ["y"]=> 55 int(0) 56 ["m"]=> 57 int(1) 58 ["d"]=> 59 int(0) 60 ["h"]=> 61 int(0) 62 ["i"]=> 63 int(0) 64 ["s"]=> 65 int(0) 66 ["f"]=> 67 float(0) 68 ["invert"]=> 69 int(0) 70 ["days"]=> 71 bool(false) 72 ["from_string"]=> 73 bool(false) 74 } 75 ["recurrences"]=> 76 int(7) 77 ["include_start_date"]=> 78 bool(false) 79 ["include_end_date"]=> 80 bool(false) 81} 82 83 84Iterate of object: 851979-01-01T09:15:00+0100 861979-02-05T09:15:00+0100 871979-03-05T09:15:00+0100 881979-04-02T09:15:00+0200 891979-05-07T09:15:00+0200 901979-06-04T09:15:00+0200 911979-07-02T09:15:00+0200 92 93 94Serialised object: 95string(%d) "O:10:"DatePeriod":7:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1979-08-06 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:3:"end";N;s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:1;s:1:"d";i:0;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;}s:11:"recurrences";i:7;s:18:"include_start_date";b:0;s:16:"include_end_date";b:0;}" 96 97 98Unserialised object: 99object(DatePeriod)#%d (%d) { 100 ["start"]=> 101 object(DateTimeImmutable)#%d (%d) { 102 ["date"]=> 103 string(26) "1978-12-22 09:15:00.000000" 104 ["timezone_type"]=> 105 int(3) 106 ["timezone"]=> 107 string(16) "Europe/Amsterdam" 108 } 109 ["current"]=> 110 object(DateTimeImmutable)#%d (%d) { 111 ["date"]=> 112 string(26) "1979-08-06 09:15:00.000000" 113 ["timezone_type"]=> 114 int(3) 115 ["timezone"]=> 116 string(16) "Europe/Amsterdam" 117 } 118 ["end"]=> 119 NULL 120 ["interval"]=> 121 object(DateInterval)#%d (%d) { 122 ["y"]=> 123 int(0) 124 ["m"]=> 125 int(1) 126 ["d"]=> 127 int(0) 128 ["h"]=> 129 int(0) 130 ["i"]=> 131 int(0) 132 ["s"]=> 133 int(0) 134 ["f"]=> 135 float(0) 136 ["invert"]=> 137 int(0) 138 ["days"]=> 139 bool(false) 140 ["from_string"]=> 141 bool(false) 142 } 143 ["recurrences"]=> 144 int(7) 145 ["include_start_date"]=> 146 bool(false) 147 ["include_end_date"]=> 148 bool(false) 149} 150 151 152Calling __serialize manually: 153array(%d) { 154 ["start"]=> 155 object(DateTimeImmutable)#%d (%d) { 156 ["date"]=> 157 string(26) "1978-12-22 09:15:00.000000" 158 ["timezone_type"]=> 159 int(3) 160 ["timezone"]=> 161 string(16) "Europe/Amsterdam" 162 } 163 ["current"]=> 164 object(DateTimeImmutable)#%d (%d) { 165 ["date"]=> 166 string(26) "1979-08-06 09:15:00.000000" 167 ["timezone_type"]=> 168 int(3) 169 ["timezone"]=> 170 string(16) "Europe/Amsterdam" 171 } 172 ["end"]=> 173 NULL 174 ["interval"]=> 175 object(DateInterval)#%d (%d) { 176 ["y"]=> 177 int(0) 178 ["m"]=> 179 int(1) 180 ["d"]=> 181 int(0) 182 ["h"]=> 183 int(0) 184 ["i"]=> 185 int(0) 186 ["s"]=> 187 int(0) 188 ["f"]=> 189 float(0) 190 ["invert"]=> 191 int(0) 192 ["days"]=> 193 bool(false) 194 ["from_string"]=> 195 bool(false) 196 } 197 ["recurrences"]=> 198 int(7) 199 ["include_start_date"]=> 200 bool(false) 201 ["include_end_date"]=> 202 bool(false) 203} 204 205 206Iterate of unserialised object: 2071979-01-01T09:15:00+0100 2081979-02-05T09:15:00+0100 2091979-03-05T09:15:00+0100 2101979-04-02T09:15:00+0200 2111979-05-07T09:15:00+0200 2121979-06-04T09:15:00+0200 2131979-07-02T09:15:00+0200 214