You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a short weekend distraction I looked a bit around in the source code which seems to be responsible for this bug.
It seems that this bug only occurs with InternalIterators. For example the following code (from a comment in the PHP docs) seems to not be affected by this issue: https://3v4l.org/P6icu
changed the title [-]DatePeriod::valid() advances DatePeriod iterator[/-][+]DatePeriod::getIterator()->valid() advances DatePeriod iterator[/+]on Feb 7, 2022
Activity
drupol commentedon Jan 21, 2022
Same issue in PHP 8.1.1
cmb69 commentedon Jan 21, 2022
Yeah, that looks wrong: https://3v4l.org/sNs51. This appears to be related to https://bugs.php.net/50981, but contrary to that issue, this really looks like an implementation bug. Anyhow, use
::isValid()as workaround.aragon999 commentedon Jan 22, 2022
For a short weekend distraction I looked a bit around in the source code which seems to be responsible for this bug.
It seems that this bug only occurs with
InternalIterators. For example the following code (from a comment in the PHP docs) seems to not be affected by this issue:https://3v4l.org/P6icu
Since the
CachingIteratorchecks that the element of the internal iterator (which is one step ahead in the actual iteration) is valid, I then looked into the code which is responsible for the validation in the case of anInternalIterator:php-src/Zend/zend_interfaces.c
Lines 587 to 600 in 024d5f4
In particular the
zend_internal_iterator_ensure_rewoundfunctionphp-src/Zend/zend_interfaces.c
Lines 514 to 526 in 024d5f4
seems to be responsible for the faulty behavior described here.
Unfortunately I have no idea how to fix this problem, since I lack understanding how it should be addressed.
TysonAndre commentedon Feb 7, 2022
This looks like an issue with DatePeriod::getIterator, not CachingIterator. https://3v4l.org/Er6ej
[-]CachingIterator::hasNext() advances DatePeriod iterator[/-][+]DatePeriod::valid() advances DatePeriod iterator[/+][-]DatePeriod::valid() advances DatePeriod iterator[/-][+]DatePeriod::getIterator()->valid() advances DatePeriod iterator[/+]TysonAndre commentedon Feb 7, 2022
Specifically, it's caused by
/* apply modification if it's not the first iteration */inext/date/php_date.cphpGH-7979: iterator advances when checking if valid
GH-7979: iterator advances when checking if valid
derickr commentedon Apr 14, 2022
This has been fixed in Git, and will be part of next month's releases.