File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -4765,6 +4765,12 @@ PHP_METHOD(DatePeriod, __construct)
47654765 }
47664766 dpobj -> start_ce = date_ce_date ;
47674767 } else {
4768+ /* check initialisation */
4769+ DATE_CHECK_INITIALIZED (Z_PHPDATE_P (start )-> time , DateTimeInterface );
4770+ if (end ) {
4771+ DATE_CHECK_INITIALIZED (Z_PHPDATE_P (end )-> time , DateTimeInterface );
4772+ }
4773+
47684774 /* init */
47694775 php_interval_obj * intobj = Z_PHPINTERVAL_P (interval );
47704776
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