Skip to content

Handle empty channel list returned as an array in getChannels - #409

Open
mkantautas wants to merge 1 commit into
pusher:masterfrom
mkantautas:fix/get-channels-empty-list
Open

mkantautas wants to merge 1 commit into
pusher:masterfrom
mkantautas:fix/get-channels-empty-list

Conversation

@mkantautas

Copy link
Copy Markdown

Description

getChannels() passes channels to get_object_vars() without checking its type. Servers that build the response from a PHP array, such as Laravel Reverb, return an empty JSON array for channels when no channel is occupied or none matches filter_by_prefix. On PHP 8 this throws a TypeError; on PHP 7 it warns and sets channels to null.

This adds the is_object() check that process_trigger_result() already uses, so an empty list stays []. Object-form channel responses are unchanged.

Fixes #408

Tested: a new unit test covers a channels object, an empty object and an empty array. It fails on master and passes with the fix on PHP 7.3 to 8.5 with prefer-lowest and prefer-stable; phplint passes. Acceptance tests were not run (they need a Pusher app).

CHANGELOG

  • [FIXED] getChannels() returns an empty channels array when the server sends the empty channel list as []

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.

getChannels() crashes on servers returning an empty channels array — the guard exists in process_trigger_result() but not here

1 participant