fix(calendar): getNextEventByGroup returns false instead of empty array#31
Open
icciaaron wants to merge 1 commit intoFreePBX:release/17.0from
Open
fix(calendar): getNextEventByGroup returns false instead of empty array#31icciaaron wants to merge 1 commit intoFreePBX:release/17.0from
icciaaron wants to merge 1 commit intoFreePBX:release/17.0from
Conversation
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>
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Calendar::getNextEventByGroup()returnsfalsewhen no calendars in a group have upcoming events. This violates the method's own@return arraydocblock and is inconsistent withBase::getNextEvent()which correctly returns[].Root Cause
When the
\$eventsarray is empty after iterating all calendars in the group,reset(\$events)returnsfalse— documented PHP behavior forreset()on empty arrays. The method should return[]to honor its contract.Impact
The
falsereturn value causes a downstream crash in the timeconditions module. Bothschedtc.phpandJob.phpaccess\$next['startdate']on the return value — PHP 8.x throws a fatalUndefined array keyerror onfalse, terminating the time condition evaluation loop and preventing BLF hint updates.Fix
[]explicitly when\$eventsis empty, matching the behavior ofBase::getNextEvent()and the@returndocblock contract\$calargument passed to the driver-levelgetNextEvent()which accepts zero parameters (harmless but incorrect)Environment
release/16.0Related
Discovered during fleet maintenance by Aaron Salsitz (Master Bitherder) at ICCI, LLC. Analysis and fix developed with Claude Code.