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.

CommentFileSizeAuthor
#8 469924.patch757 bytesbradweikel

Comments

brianbrown’s picture

I have this issue also!
-Brian

brianbrown’s picture

Many, many modules installed.

Anonymous’s picture

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

javajones’s picture

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.

brianbrown’s picture

Not for me!

bradweikel’s picture

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.

obeygiant’s picture

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';

bradweikel’s picture

Status: Active » Needs review
StatusFileSize
new757 bytes

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.

obeygiant’s picture

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.

coryms’s picture

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