Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -5206,6 +5206,23 @@ PHP_METHOD(DatePeriod, createFromISO8601String)
}
}

static void date_period_reset(php_period_obj *period_obj)
{
if (period_obj->start) {
timelib_time_dtor(period_obj->start);
}
if (period_obj->current) {
timelib_time_dtor(period_obj->current);
}
if (period_obj->end) {
timelib_time_dtor(period_obj->end);
}
if (period_obj->interval) {
timelib_rel_time_dtor(period_obj->interval);
}
memset(period_obj, 0, XtOffsetOf(php_period_obj, std));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
memset(period_obj, 0, XtOffsetOf(php_period_obj, std));
memset(period_obj, 0, offsetof(php_period_obj, std));

We only removed XtOffsetOf with 8.6, but offsetof() is reliably available even for 8.4.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remembered your change. Will have to be backported to 8.2, so I'd prefer just changing on master to match your other PR.

}

/* {{{ Creates new DatePeriod object. */
PHP_METHOD(DatePeriod, __construct)
{
Expand All @@ -5227,7 +5244,7 @@ PHP_METHOD(DatePeriod, __construct)
}

dpobj = Z_PHPPERIOD_P(ZEND_THIS);
dpobj->current = NULL;
date_period_reset(dpobj);

if (isostr) {
zend_error(E_DEPRECATED, "Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, "
Expand All @@ -5245,6 +5262,7 @@ PHP_METHOD(DatePeriod, __construct)
if (end) {
DATE_CHECK_INITIALIZED(Z_PHPDATE_P(end)->time, date_ce_interface);
}
DATE_CHECK_INITIALIZED(Z_PHPINTERVAL_P(interval)->initialized, Z_OBJCE_P(interval));

/* init */
php_interval_obj *intobj = Z_PHPINTERVAL_P(interval);
Expand Down
14 changes: 14 additions & 0 deletions ext/date/tests/DatePeriod_double_constructor_call.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Double DatePeriod::__construct() call
--FILE--
<?php

$start = new \DateTime();
$interval = new \DateInterval('P1D');
$period = new \DatePeriod($start, $interval, 1);
$period->__construct($start, $interval, 1);

?>
===DONE===
--EXPECT--
===DONE===
Loading