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.

AttachmentSize
location.patch1.42 KB

#1

agentrickard - November 5, 2009 - 16:04
Status:active» reviewed & tested by the community

Confirmed.

#2

nickl - November 26, 2009 - 05:45
Status:reviewed & tested by the community» needs work

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 :
<?php
 
if (is_array($fields)) {
    foreach (
$fields as $key => $value) {
     
//snip
   
}
  }
?>

Because the foreach will still fail if $fields = 3; for example.

#3

nickl - December 3, 2009 - 17:45
Status:needs work» needs review

Rolled new patch with above suggestions implemented.

AttachmentSize
location_26.patch 1.53 KB
 
 

Drupal is a registered trademark of Dries Buytaert.