Download & Extend

Warning after module activation

Project:Activism
Version:6.x-2.0
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

Hi,

when I activate activism module, Drupal return this messages :

warning: in_array() [function.in-array]: Wrong datatype for second argument in /var/www/drupal/sites/all/modules/activism/activism.module on line 612.

Comments

#1

I have this issue also!
-Brian

#2

Many, many modules installed.

#3

I think this could be a callback issue, like a conflict between a callback in the module and some other path setting. What other modules do you have installed?

M

#4

I go the following warning, but it went away after I enabled the petition module:

* warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/bobo/public_html/ahora/modules/activism/activism.module on line 612.
* warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/bobo/public_html/ahora/modules/activism/activism.module on line 612.

#5

Not for me!

#6

Just to confirm --

On a fresh install, I enabled only the Activism module, and got one warning.
Then I enabled the Petition module and it went away.

Glancing at the code, it looks like you just need to initialize $activism_cta_forms in activism_form_alter, ie "$activism_cta_forms = array();"

Don't have time to test and patch right now, though. Sorry.

#7

Just to clarify for the noob, are you referring to line 612?

if (in_array($form['form_id']['#value'], $activism_cta_forms)) {

or are you referring to line 607

$activism_cta_forms[] = $cta_type['module'] . '_activism_cta_form';

#8

Status:active» needs review

Patch attached.

Mini PHP lesson for obeygiant:
On line 612, $activism_cta_forms is passed to the in_array function, and in_array assumes that it is in fact an array.

However, the only place that $activism_cta_forms is set is on line 607, which is inside a foreach loop (606-608). So if the loop is executed zero times, $activism_cta_forms is not defined, and line 612 throws a warning.

My patch just makes sure that $activism_cta_forms is always initialized by adding the following line BEFORE the foreach loop:
$activism_cta_forms = array();

It turns out this is sort of a non-bug, because PHP handles the situation the way we want, but it's a good best practice to get rid of warnings like this.

AttachmentSize
469924.patch 757 bytes

#9

Thank you for the tutorial,the patch and for handling the question with "kid gloves" as I'm obviously still learning. This is why I defer to those that are more knowledgeable than myself.

#10

Worked for me! Thanks. Added $activism_cta_forms = array(); and errors went away.

nobody click here