Bug #71454 [Com]: foreach last element is copy of penultimate, with array of DateIntervals
| From: | qdinar at gmail dot com | Date: | Tue, 26 Jan 2016 11:54:50 +0000 |
| Subject: | Bug #71454 [Com]: foreach last element is copy of penultimate, with array of DateIntervals | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-198901@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71454&edit=1
ID: 71454
Comment by: qdinar at gmail dot com
Reported by: qdinar at gmail dot com
Summary: foreach last element is copy of penultimate, with
array of DateIntervals
Status: Open
Type: Bug
Package: Date/time related
Operating System: windows 10
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
i have found a quick fix / workaround for this bug: use foreach($intervals as &$interv) (ie
&$interv also in second foreach).
Previous Comments:
------------------------------------------------------------------------
[2016-01-26 11:51:34] qdinar at gmail dot com
Description:
------------
foreach through array of DateIntervals gives penultimate element instead of last element
Test script:
---------------
$intervals=array(1,2,3,4,5,6);
foreach($intervals as &$interv){
$interv = new DateInterval('PT'.$interv.'M');
}
$time = new DateTime('6:20');
foreach($intervals as $interv){
echo ','.$interv->format('%i');
}
Expected result:
----------------
,1,2,3,4,5,6
Actual result:
--------------
,1,2,3,4,5,5
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71454&edit=1