Hello, I've these warnings on my node type contemplate page and the page of my content type.

warning: Invalid argument supplied for foreach() in /home/pariscin/www/sites/all/modules/contemplate/contemplate.module(833) : eval()'d code on line 38.
warning: Invalid argument supplied for foreach() in /home/pariscin/www/sites/all/modules/contemplate/contemplate.module(833) : eval()'d code on line 60.

It's because I'm using this code. If I'm using only one field. I've only one warnng.

<?php
  $puntuacion = "";
  $i = 0;
  $max = count($field_xxx);
  foreach ($field_xxx as $item) {
    $puntuacion = (++$i < $max) ? " - " : $puntuacion = "";
	
	if($node->field_xxx[0]['view']!="") 
	
    print $item['view'].''.$puntuacion.' ';
};
?>


<?php
  $puntuacion = "";
  $i = 0;
  $max = count($field_yyy);
  foreach ($field_yyys as $item) {
    $puntuacion = (++$i < $max) ? " | " : $puntuacion = "";
    print $item['view'].''.$puntuacion.' ';
};
?>

The weird thing is that I'm using this code in another node type with contemplate too and all is workinf fine. No warnings.
It's why is a bug report issue.

Anybody has an idea to remove the warnings?

Thanks

Comments

junro’s picture

Forgot to say I have the warnings only with nodes where field_xxx and field_yyy have no values.

montaldipa’s picture

You should be able to type cast $field_xxx and $field_yyy. For example...

foreach ($field_xxx as $item) {

...becomes...

foreach ((array)$field_xxx as $item) {

This should make the warning go away.

Reference: http://www.php.net/manual/en/language.types.type-juggling.php

junro’s picture

Category: bug » support
Status: Active » Fixed

Thanks a lot! I don't have the warnings anymore :)

and thanks for the link! Very usefull ^^

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.