xref: /PHP-8.3/ext/date/tests/bug52808.phpt (revision b7860cd5)
1--TEST--
2Bug #52808 (Segfault when specifying interval as two dates)
3--FILE--
4<?php
5date_default_timezone_set('Europe/Oslo');
6$intervals = array(
7	/* Three correct sets*/
8    "2008-05-11T15:30:00Z/2007-03-01T13:00:00Z",
9    "2007-05-11T15:30:00Z/2008-03-01T13:00:00Z",
10    "2007-05-11T15:30:00Z 2008-03-01T13:00:00Z",
11	/* Error situations */
12    "2007-05-11T15:30:00Z/",
13    "2007-05-11T15:30:00Z",
14    "2007-05-11T15:30:00Z/:00Z",
15);
16foreach($intervals as $iv) {
17    try
18    {
19        $di = new DateInterval($iv);
20        var_dump($di);
21    }
22    catch ( \DateMalformedIntervalStringException $e )
23    {
24        echo $e::class, ': ', $e->getMessage(), "\n";
25    }
26}
27echo "==DONE==\n";
28?>
29--EXPECTF--
30object(DateInterval)#%d (%d) {
31  ["y"]=>
32  int(1)
33  ["m"]=>
34  int(2)
35  ["d"]=>
36  int(10)
37  ["h"]=>
38  int(2)
39  ["i"]=>
40  int(30)
41  ["s"]=>
42  int(0)
43  ["f"]=>
44  float(0)
45  ["invert"]=>
46  int(1)
47  ["days"]=>
48  int(437)
49  ["from_string"]=>
50  bool(false)
51}
52object(DateInterval)#%d (%d) {
53  ["y"]=>
54  int(0)
55  ["m"]=>
56  int(9)
57  ["d"]=>
58  int(18)
59  ["h"]=>
60  int(21)
61  ["i"]=>
62  int(30)
63  ["s"]=>
64  int(0)
65  ["f"]=>
66  float(0)
67  ["invert"]=>
68  int(0)
69  ["days"]=>
70  int(294)
71  ["from_string"]=>
72  bool(false)
73}
74object(DateInterval)#%d (%d) {
75  ["y"]=>
76  int(0)
77  ["m"]=>
78  int(9)
79  ["d"]=>
80  int(18)
81  ["h"]=>
82  int(21)
83  ["i"]=>
84  int(30)
85  ["s"]=>
86  int(0)
87  ["f"]=>
88  float(0)
89  ["invert"]=>
90  int(0)
91  ["days"]=>
92  int(294)
93  ["from_string"]=>
94  bool(false)
95}
96DateMalformedIntervalStringException: Failed to parse interval (2007-05-11T15:30:00Z/)
97DateMalformedIntervalStringException: Failed to parse interval (2007-05-11T15:30:00Z)
98DateMalformedIntervalStringException: Unknown or bad format (2007-05-11T15:30:00Z/:00Z)
99==DONE==
100