xref: /PHP-8.3/ext/date/tests/bug44562.phpt (revision 9c7c0a0b)
1--TEST--
2Bug #44562 (Creating instance of DatePeriod crashes)
3--FILE--
4<?php
5date_default_timezone_set('Europe/Oslo');
6
7try {
8    $dp = new DatePeriod('2D');
9} catch (Exception $e) {
10    echo $e::class, ': ', $e->getMessage(), "\n";
11}
12
13try {
14    DatePeriod::createFromISO8601String('2D');
15} catch (Exception $e) {
16    echo $e::class, ': ', $e->getMessage(), "\n";
17}
18
19$begin = new DateTime( "2008-07-20T22:44:53+0200" );
20$interval = DateInterval::createFromDateString( "1 day" );
21
22$dp = new DatePeriod( $begin, $interval, 10 );
23foreach ( $dp as $d )
24{
25    var_dump ($d->format( DATE_ISO8601 ) );
26}
27
28?>
29--EXPECT--
30DateMalformedPeriodStringException: Unknown or bad format (2D)
31DateMalformedPeriodStringException: Unknown or bad format (2D)
32string(24) "2008-07-20T22:44:53+0200"
33string(24) "2008-07-21T22:44:53+0200"
34string(24) "2008-07-22T22:44:53+0200"
35string(24) "2008-07-23T22:44:53+0200"
36string(24) "2008-07-24T22:44:53+0200"
37string(24) "2008-07-25T22:44:53+0200"
38string(24) "2008-07-26T22:44:53+0200"
39string(24) "2008-07-27T22:44:53+0200"
40string(24) "2008-07-28T22:44:53+0200"
41string(24) "2008-07-29T22:44:53+0200"
42string(24) "2008-07-30T22:44:53+0200"
43