File tree 3 files changed +38
-0
lines changed
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ PHP NEWS
11
11
- Core:
12
12
. Fixed strerror_r detection at configuration time. (Kévin Dunglas)
13
13
14
+ - Date:
15
+ . Fixed bug GH-11416: Crash with DatePeriod when uninitialised objects
16
+ are passed in. (Derick)
17
+
14
18
- DOM:
15
19
. Fix DOMEntity field getter bugs. (nielsdos)
16
20
. Fix incorrect attribute existence check in DOMElement::setAttributeNodeNS.
Original file line number Diff line number Diff line change @@ -4338,6 +4338,12 @@ PHP_METHOD(DatePeriod, __construct)
4338
4338
}
4339
4339
dpobj -> start_ce = date_ce_date ;
4340
4340
} else {
4341
+ /* check initialisation */
4342
+ DATE_CHECK_INITIALIZED (Z_PHPDATE_P (start )-> time , DateTimeInterface );
4343
+ if (end ) {
4344
+ DATE_CHECK_INITIALIZED (Z_PHPDATE_P (end )-> time , DateTimeInterface );
4345
+ }
4346
+
4341
4347
/* init */
4342
4348
php_interval_obj * intobj = Z_PHPINTERVAL_P (interval );
4343
4349
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug GH-11416: Crash with DatePeriod when uninitialised objects are passed in
3
+ --INI--
4
+ date.timezone=UTC
5
+ --FILE--
6
+ <?php
7
+ $ now = new DateTimeImmutable ();
8
+
9
+ $ date = (new ReflectionClass (DateTime::class))->newInstanceWithoutConstructor ();
10
+ try {
11
+ new DatePeriod ($ date , new DateInterval ('P1D ' ), 2 );
12
+ } catch (Error $ e ) {
13
+ echo get_class ($ e ), ': ' , $ e ->getMessage (), "\n" ;
14
+ }
15
+
16
+ $ date = (new ReflectionClass (DateTime::class))->newInstanceWithoutConstructor ();
17
+ try {
18
+ new DatePeriod ($ now , new DateInterval ('P1D ' ), $ date );
19
+ } catch (Error $ e ) {
20
+ echo get_class ($ e ), ': ' , $ e ->getMessage (), "\n" ;
21
+ }
22
+
23
+ echo "OK \n" ;
24
+ ?>
25
+ --EXPECT--
26
+ Error: The DateTimeInterface object has not been correctly initialized by its constructor
27
+ Error: The DateTimeInterface object has not been correctly initialized by its constructor
28
+ OK
You can’t perform that action at this time.
0 commit comments