Invalid foreach line 1445
nrussell - October 28, 2009 - 18:41
| Project: | Location |
| Version: | 6.x-3.1-rc1 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
In reviewing this issue, I also noticed there was another foreach in this function not properly being checked. It is important PHP practice to insure that the array you attempting to iterate through inside a foreach is first checked for data. PHP will generated a warning if the array does not exists inside a foreach statement.
Attached is a patch for these two conditions.
| Attachment | Size |
|---|---|
| location.patch | 1.42 KB |

#1
Confirmed.
#2
Should the protecting if statements not check for arrays instead of checking if the value is set positively.
<?php
if (is_array($variables['hide'])) {
foreach($variables['hide'] as $key) {
//snip
}
}
?>
And also :
<?phpif (is_array($fields)) {
foreach ($fields as $key => $value) {
//snip
}
}
?>
Because the foreach will still fail if $fields = 3; for example.
#3
Rolled new patch with above suggestions implemented.