warning messages from array functions in various places
dharmatech - December 11, 2008 - 19:43
| Project: | Formfilter |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
In several locations, array functions may be called with null arguments where an array is required. This produces a distracting warning message. One good solution is to apply the (array) cast to any array type argument that might be null. Here is a patch against 6.x-1.x-dev (Nov. 25, 08) which suppresses two such messages:
===================================================================
--- formfilter_ui/formfilter_ui.module (revision 2236)
+++ formfilter_ui/formfilter_ui.module (working copy)
@@ -90,7 +90,7 @@
if ((!$_REQUEST['formfilter_id']) && array_key_exists($form_id, $filters) && ((!user_access('view forms without filtering') || $_REQUEST['formfilter_preview']))) {
$form_filters = array();
// Convert filters to arrays.
- foreach (array_keys($filters[$form_id]) as $filter) {
+ foreach ((array)array_keys($filters[$form_id]) as $filter) {
$form_filters[] = explode('|', $filter);
}
if ($_REQUEST['formfilter_preview']) {
@@ -142,7 +142,7 @@
*/
function formfilter_ui_form_validate($form, &$form_state) {
$filters = variable_get('formfilter', array());
- $filters[$form_state['values']['form_id']] = array_filter($_REQUEST['edit']['formfilter']);
+ $filters[$form_state['values']['form_id']] = array_filter((array)$_REQUEST['edit']['formfilter']);
variable_set('formfilter', $filters);
drupal_set_message(t('Form filtering registered.'));
drupal_goto($_GET['q']);
#1
Here is a typical error that this causes:
warning: array_filter() [function.array-filter]: The first argument should be an array in ... modules/formfilter/formfilter_ui/formfilter_ui.module on line 145.
I am putting this here so that people can find this post. Thanks for the patch above, it works for me. I recreated it though because when I tried to apply it I got the message "malformed patch at line 5".
I am including it as a file and marking it as needs review.