Birthdays hook can throw foreach loop error
Submitted Jason H, Apr 04 2012 10:06 AM | Last updated Apr 04 2012 10:06 AM
If a user doesn't have access to any calendars, the birthday hook code can cause
Warning: Invalid argument supplied for foreach() in /admin/applications_addon/ips/calendar/sources/hooks.php on line 151
To
Seems to clear it.. I went with ! empty because count and if ($calendars) has given me fits.. Any should probably work though.
Warning: Invalid argument supplied for foreach() in /admin/applications_addon/ips/calendar/sources/hooks.php on line 151
foreach( $calendars as $calendar )
{
/* We need to grab first calendar that allows birthdays */
if( !$calendar['cal_bday_limit'] )
{
continue;
}
$data = array(
'id' => $calendar['cal_id'],
'title' => $calendar['cal_title_seo'],
'year' => $year,
'month' => $month,
'day' => $day,
);
break;
}
To
if (! empty($calendars) )
{
foreach( $calendars as $calendar )
{
/* We need to grab first calendar that allows birthdays */
if( !$calendar['cal_bday_limit'] )
{
continue;
}
$data = array(
'id' => $calendar['cal_id'],
'title' => $calendar['cal_title_seo'],
'year' => $year,
'month' => $month,
'day' => $day,
);
break;
}
}
Seems to clear it.. I went with ! empty because count and if ($calendars) has given me fits.. Any should probably work though.
| Status: | Fixed |
| Version: | 3.3.0 |
| Fixed In: | 3.3.1 |











7 Comments
to
This should resolve the warning, but has the secondary benefit that it ensures the returned data type from a call to getCalendars() is consistent for other methods that are calling it (i.e. to prevent potential similar bugs elsewhere).