Skip to content

Fix TypeError in groups.php when database operations fail#6

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-count-typeerror-in-groups
Draft

Fix TypeError in groups.php when database operations fail#6
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-count-typeerror-in-groups

Conversation

Copy link

Copilot AI commented Feb 4, 2026

database->select() returns false on connection failure or PDO exceptions. Calling count() on this in PHP 8+ causes a fatal TypeError, preventing system initialization during upgrades.

Changes

  • Line 462: Guard count($result) with is_array() check
  • Line 531: Guard $num_rows === 0 comparison with !== false check
  • Both checks use strict comparison (===) to prevent type coercion
// Before
if (count($result) == 0) {

// After  
if (is_array($result) && count($result) === 0) {

When database operations fail, the code now skips default group/permission creation instead of crashing.

Original prompt

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /var/www/fusionpbx/resources/classes/groups.php:462 Stack trace: #0 /var/www/fusionpbx/resources/classes/menu.php(1099): groups->defaults() #1 /var/www/fusionpbx/core/menu/menu_restore_default.php(58): menu->restore_default() #2 /var/www/fusionpbx/core/upgrade/index.php(182): require_once('...') #3 {main} thrown in /var/www/fusionpbx/resources/classes/groups.php on line 462 - please make it simplest , database added sussecsfully but should not auto config mod_nibblebill_conf.xml because fusionpbx has built in script editor and better add it manuall -even fusionpbx based on freeswitch and it's control with fudionpbx script


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 4, 2026 07:48
Co-authored-by: mostakinads-design <258886467+mostakinads-design@users.noreply.github.com>
Co-authored-by: mostakinads-design <258886467+mostakinads-design@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TypeError in groups.php related to count() function Fix TypeError in groups.php when database operations fail Feb 4, 2026
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.

2 participants