Bug #79104 [NEW]: Relative DateInterval Creates Infinite Loop

From: Date: Sat, 11 Jan 2020 21:42:39 +0000
Subject: Bug #79104 [NEW]: Relative DateInterval Creates Infinite Loop
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224856@lists.php.net to get a copy of this message
From: jimbo2150 at gmail dot com Operating system: PHP version: 7.3.13 Package: Date/time related Bug Type: Bug Bug description:Relative DateInterval Creates Infinite Loop Description: ------------ A relative date format used in DateInterval produces and infinite loop when used with DatePeriod. An example is looking for the first Monday in January of each year. When iterated via DatePeriod the year will not get iterated and the correct relative date for current year keeps getting returned creating an infinite loop. Test script: --------------- // Looking for every Monday of January each year $fmj = DateInterval::createFromDateString('first Monday of January'); $period = new DatePeriod(new DateTime('2020-01-01'), $fmj, new DateTime('2022-01-11')); // Infinite loop, first Monday of January of current year keeps getting iterated foreach ($period as $dt) { var_dump($dt->format("l Y-m-d H:i:s")); } Expected result: ---------------- Return each first Monday of January for the next 2 years. string(30) "Wednesday 2020-01-01 00:00:00" string(27) "Monday 2020-01-06 00:00:00" string(27) "Monday 2021-01-04 00:00:00" string(27) "Monday 2022-01-03 00:00:00" Actual result: -------------- Infinite loop where each date is the first Monday of the current year's January. string(30) "Wednesday 2020-01-01 00:00:00" string(27) "Monday 2020-01-06 00:00:00" string(27) "Monday 2020-01-06 00:00:00" string(27) "Monday 2020-01-06 00:00:00" string(27) "Monday 2020-01-06 00:00:00" string(27) "Monday 2020-01-06 00:00:00" string(27) "Monday 2020-01-06 00:00:00" string(27) "Monday 2020-01-06 00:00:00" string(27) "Monday 2020-01-06 00:00:00" ... {infinite loop} -- Edit bug report at https://bugs.php.net/bug.php?id=79104&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79104&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79104&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79104&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79104&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79104&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79104&r=support Expected behavior: https://bugs.php.net/fix.php?id=79104&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79104&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79104&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79104&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79104&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79104&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79104&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79104&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79104&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79104&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79104&r=mysqlcfg

« previous php.bugs (#224856) next »