Skip to content

fix(calendar): getNextEventByGroup returns false instead of empty array#31

Open
icciaaron wants to merge 1 commit intoFreePBX:release/17.0from
icciaaron:fix/getNextEventByGroup-empty-return
Open

fix(calendar): getNextEventByGroup returns false instead of empty array#31
icciaaron wants to merge 1 commit intoFreePBX:release/17.0from
icciaaron:fix/getNextEventByGroup-empty-return

Conversation

@icciaaron
Copy link
Copy Markdown

Summary

Calendar::getNextEventByGroup() returns false when no calendars in a group have upcoming events. This violates the method's own @return array docblock and is inconsistent with Base::getNextEvent() which correctly returns [].

Root Cause

When the \$events array is empty after iterating all calendars in the group, reset(\$events) returns false — documented PHP behavior for reset() on empty arrays. The method should return [] to honor its contract.

Impact

The false return value causes a downstream crash in the timeconditions module. Both schedtc.php and Job.php access \$next['startdate'] on the return value — PHP 8.x throws a fatal Undefined array key error on false, terminating the time condition evaluation loop and preventing BLF hint updates.

Fix

  1. Return [] explicitly when \$events is empty, matching the behavior of Base::getNextEvent() and the @return docblock contract
  2. Remove spurious \$cal argument passed to the driver-level getNextEvent() which accepts zero parameters (harmless but incorrect)

Environment

  • FreePBX 17 / PBXact 17
  • PHP 8.1+ (Debian 12)
  • Same bug exists in release/16.0

Related


Discovered during fleet maintenance by Aaron Salsitz (Master Bitherder) at ICCI, LLC. Analysis and fix developed with Claude Code.

When no calendars in a group have upcoming events, the $events array
is empty after the foreach loop. PHP's reset() on an empty array
returns false, not []. This is inconsistent with Base::getNextEvent()
which correctly returns [] when no events are found.

The false return value causes a downstream crash in the timeconditions
module (schedtc.php, Job.php) when it accesses $next['startdate'] —
PHP 8.x throws "Undefined array key" on false.

Return [] explicitly when $events is empty to honor the @return
docblock contract ("the Found event or empty") and match the
behavior of getNextEvent().

Also remove spurious $cal argument passed to the driver-level
getNextEvent() which accepts zero parameters.

Reported-by: Aaron Salsitz <asalsitz@icci.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
@icciaaron
Copy link
Copy Markdown
Author

Hi @Akarsh04 @prasanthcode4 — small one here, sibling to #32. getNextEventByGroup was returning false instead of an empty array, causing downstream count()/foreach() warnings under PHP 8. Would appreciate a look when you have bandwidth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant