1--TEST-- 2Test that calling DatePeriod::__unserialize() directly with wrong argument type throws 3--FILE-- 4<?php 5 6$start = new DateTime("2022-07-14 00:00:00", new DateTimeZone("UTC")); 7$interval = new DateInterval('P1D'); 8$end = new DateTime("2022-07-16 00:00:00", new DateTimeZone("UTC")); 9$period = new DatePeriod($start, $interval, $end); 10 11try { 12 $period->__unserialize( 13 [ 14 "current" => new DateTime("2024-08-27 00:00:00"), 15 "start" => new DateTime("2024-08-28 00:00:00"), 16 "end" => new DateTime("2024-08-29 00:00:00"), 17 "interval" => new DateInterval('P2D'), 18 "recurrences" => 2, 19 "include_start_date" => "wrong type", 20 "include_end_date" => true, 21 ] 22 ); 23} catch (\Error $e) { 24 echo $e::class, ': ', $e->getMessage(), "\n"; 25} 26 27var_dump($period); 28 29?> 30--EXPECTF-- 31Error: Invalid serialization data for DatePeriod object 32object(DatePeriod)#%d (%d) { 33 ["start"]=> 34 object(DateTime)#%d (%d) { 35 ["date"]=> 36 string(26) "2024-08-28 00:00:00.000000" 37 ["timezone_type"]=> 38 int(3) 39 ["timezone"]=> 40 string(3) "UTC" 41 } 42 ["current"]=> 43 object(DateTime)#%d (%d) { 44 ["date"]=> 45 string(26) "2024-08-27 00:00:00.000000" 46 ["timezone_type"]=> 47 int(3) 48 ["timezone"]=> 49 string(3) "UTC" 50 } 51 ["end"]=> 52 object(DateTime)#%d (%d) { 53 ["date"]=> 54 string(26) "2024-08-29 00:00:00.000000" 55 ["timezone_type"]=> 56 int(3) 57 ["timezone"]=> 58 string(3) "UTC" 59 } 60 ["interval"]=> 61 object(DateInterval)#%d (%d) { 62 ["y"]=> 63 int(0) 64 ["m"]=> 65 int(0) 66 ["d"]=> 67 int(2) 68 ["h"]=> 69 int(0) 70 ["i"]=> 71 int(0) 72 ["s"]=> 73 int(0) 74 ["f"]=> 75 float(0) 76 ["invert"]=> 77 int(0) 78 ["days"]=> 79 bool(false) 80 ["from_string"]=> 81 bool(false) 82 } 83 ["recurrences"]=> 84 int(2) 85 ["include_start_date"]=> 86 bool(true) 87 ["include_end_date"]=> 88 bool(false) 89} 90