Can't use remove() in a loop
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
CoughPHP |
Fix Committed
|
Medium
|
Anthony Bush | ||
1.4 |
Fix Committed
|
Medium
|
Anthony Bush |
Bug Description
The following code does not work (for collections containing more than one element):
<?php
foreach ($collection as $element) {
$collection-
}
assert(
Only the first element is removed. However, this code does work:
<?php
foreach ($collection as $element) {
$collection-
}
assert(
and this works too:
<?php
foreach ($collection as $element) {
unset(
}
assert(
I've found that the reason for this is due to CoughCollection saving the removed element (for later processing) AFTER the unset is performed.
$this-
$this-
Changing this to:
$this-
$this-
fixes the problem. There's two places in CoughCollection to fix, removeByKey(), and removeByReferen
Changed in coughphp: | |
status: | Confirmed → Fix Committed |