[php-src] Issue #7979: DatePeriod::getIterator()->valid() advances DatePeriod iterator
| From: | TysonAndre | Date: | Mon, 07 Feb 2022 14:46:25 +0000 |
| Subject: | [php-src] Issue #7979: DatePeriod::getIterator()->valid() advances DatePeriod iterator | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-239540@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7979
Comment Author: TysonAndre
Specifically, it's caused by
/* apply modification if it's not the first iteration
*/ in ext/date/php_date.c
```c
// ext/date/php_date.c
/* iterator handler table */
static const zend_object_iterator_funcs date_period_it_funcs = {
date_period_it_dtor,
date_period_it_has_more,
// ...
/* {{{ date_period_it_has_more */
static int date_period_it_has_more(zend_object_iterator *iter)
{
// ext/date/php_date.c
date_period_it *iterator = (date_period_it *)iter;
php_period_obj *object = Z_PHPPERIOD_P(&iterator->intern.data);
timelib_time *it_time = object->current;
/* apply modification if it's not the first iteration */
if (!object->include_start_date || iterator->current_index > 0) {
it_time->have_relative = 1;
it_time->relative = *object->interval;
it_time->sse_uptodate = 0;
timelib_update_ts(it_time, NULL);
timelib_update_from_sse(it_time);
}
if (object->end) {
return object->current->sse < object->end->sse ? SUCCESS : FAILURE;
} else {
return (iterator->current_index < object->recurrences) ? SUCCESS : FAILURE;
}
}
/* }}} */
```