1--TEST-- 2Bug #53437 (Crash when using unserialized DatePeriod instance), variation 1 3--FILE-- 4<?php 5$dp = new DatePeriod(new DateTime('2010-01-01 UTC'), new DateInterval('P1D'), 2); 6 7echo "Original:\r\n"; 8foreach($dp as $dt) { 9 echo $dt->format('Y-m-d H:i:s')."\r\n"; 10} 11echo "\r\n"; 12var_dump($dp); 13 14$ser = serialize($dp); // $ser is: O:10:"DatePeriod":0:{} 15 16// Create dangerous instance 17$dpu = unserialize($ser); // $dpu has invalid values??? 18var_dump($dpu); 19 20echo "Unserialized:\r\n"; 21foreach($dpu as $dt) { 22 echo $dt->format('Y-m-d H:i:s')."\r\n"; 23} 24?> 25==DONE== 26--EXPECTF-- 27Original: 282010-01-01 00:00:00 292010-01-02 00:00:00 302010-01-03 00:00:00 31 32object(DatePeriod)#%d (6) { 33 ["start"]=> 34 object(DateTime)#%d (3) { 35 ["date"]=> 36 string(26) "2010-01-01 00:00:00.000000" 37 ["timezone_type"]=> 38 int(3) 39 ["timezone"]=> 40 string(3) "UTC" 41 } 42 ["current"]=> 43 object(DateTime)#%d (3) { 44 ["date"]=> 45 string(26) "2010-01-04 00:00:00.000000" 46 ["timezone_type"]=> 47 int(3) 48 ["timezone"]=> 49 string(3) "UTC" 50 } 51 ["end"]=> 52 NULL 53 ["interval"]=> 54 object(DateInterval)#%d (16) { 55 ["y"]=> 56 int(0) 57 ["m"]=> 58 int(0) 59 ["d"]=> 60 int(1) 61 ["h"]=> 62 int(0) 63 ["i"]=> 64 int(0) 65 ["s"]=> 66 int(0) 67 ["f"]=> 68 float(0) 69 ["weekday"]=> 70 int(0) 71 ["weekday_behavior"]=> 72 int(0) 73 ["first_last_day_of"]=> 74 int(0) 75 ["invert"]=> 76 int(0) 77 ["days"]=> 78 bool(false) 79 ["special_type"]=> 80 int(0) 81 ["special_amount"]=> 82 int(0) 83 ["have_weekday_relative"]=> 84 int(0) 85 ["have_special_relative"]=> 86 int(0) 87 } 88 ["recurrences"]=> 89 int(3) 90 ["include_start_date"]=> 91 bool(true) 92} 93object(DatePeriod)#%d (6) { 94 ["start"]=> 95 object(DateTime)#%d (3) { 96 ["date"]=> 97 string(26) "2010-01-01 00:00:00.000000" 98 ["timezone_type"]=> 99 int(3) 100 ["timezone"]=> 101 string(3) "UTC" 102 } 103 ["current"]=> 104 object(DateTime)#%d (3) { 105 ["date"]=> 106 string(26) "2010-01-04 00:00:00.000000" 107 ["timezone_type"]=> 108 int(3) 109 ["timezone"]=> 110 string(3) "UTC" 111 } 112 ["end"]=> 113 NULL 114 ["interval"]=> 115 object(DateInterval)#%d (16) { 116 ["y"]=> 117 int(0) 118 ["m"]=> 119 int(0) 120 ["d"]=> 121 int(1) 122 ["h"]=> 123 int(0) 124 ["i"]=> 125 int(0) 126 ["s"]=> 127 int(0) 128 ["f"]=> 129 float(0) 130 ["weekday"]=> 131 int(0) 132 ["weekday_behavior"]=> 133 int(0) 134 ["first_last_day_of"]=> 135 int(0) 136 ["invert"]=> 137 int(0) 138 ["days"]=> 139 bool(false) 140 ["special_type"]=> 141 int(0) 142 ["special_amount"]=> 143 int(0) 144 ["have_weekday_relative"]=> 145 int(0) 146 ["have_special_relative"]=> 147 int(0) 148 } 149 ["recurrences"]=> 150 int(3) 151 ["include_start_date"]=> 152 bool(true) 153} 154Unserialized: 1552010-01-01 00:00:00 1562010-01-02 00:00:00 1572010-01-03 00:00:00 158==DONE== 159