Skip to content

[1.x] fix(search): coalesce null query before gambits to avoid str_getcsv deprecation - #4812

Merged
imorland merged 4 commits into
flarum:1.xfrom
edgeinfinity1:1.x
Aug 3, 2026
Merged

[1.x] fix(search): coalesce null query before gambits to avoid str_getcsv deprecation#4812
imorland merged 4 commits into
flarum:1.xfrom
edgeinfinity1:1.x

Conversation

@edgeinfinity1

@edgeinfinity1 edgeinfinity1 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

This fixed an issue I came across when:

  • Use PHP 8.2+
  • Navigate to users list
  • Refresh page
  • A deprecation warning shows saying $query should not be null.

I'm not 100% sure if this is actually core related or my extension issue, but I tested without search related extensions and it persists.

Changes proposed in this pull request:

Reviewers should focus on:

Screenshot

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Required changes:

  • Related documentation PR: (Remove if irrelevant)

@edgeinfinity1
edgeinfinity1 requested a review from a team as a code owner July 13, 2026 08:51
@edgeinfinity1

edgeinfinity1 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

I reproduced the exception:

Deprecated: str_getcsv(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/192.168.5.132/vendor/flarum/core/src/Search/GambitManager.php on line 69

Fatal error: Uncaught Laminas\HttpHandlerRunner\Exception\EmitterException: Output has been emitted previously; cannot emit response in /www/wwwroot/192.168.5.132/vendor/laminas/laminas-httphandlerrunner/src/Exception/EmitterException.php:21 Stack trace: #0 /www/wwwroot/192.168.5.132/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitterTrait.php(42): Laminas\HttpHandlerRunner\Exception\EmitterException::forOutputSent() #1 /www/wwwroot/192.168.5.132/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitter.php(22): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->assertNoPreviousOutput() #2 /www/wwwroot/192.168.5.132/vendor/laminas/laminas-httphandlerrunner/src/RequestHandlerRunner.php(75): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->emit() #3 /www/wwwroot/192.168.5.132/vendor/flarum/core/src/Http/Server.php(45): Laminas\HttpHandlerRunner\RequestHandlerRunner->run() #4 /www/wwwroot/192.168.5.132/public/index.php(26): Flarum\Http\Server->listen() #5 {main} thrown in /www/wwwroot/192.168.5.132/vendor/laminas/laminas-httphandlerrunner/src/Exception/EmitterException.php on line 21

The checks say that $query should never be null, but it went null in my case.
Together with my php flarum info:

Details
Flarum core: 1.8.17
PHP version: CLI: 8.2.31, Web: 8.2.31
PHP memory limit: CLI: 1024M, Web: unable to detect
MySQL version: 5.7.42-log
Loaded extensions: Core, date, libxml, openssl, pcre, sqlite3, zlib, bcmath, ctype, curl, dom, filter, ftp, gd, gettext, hash, iconv, intl, json, mbstring, SPL, session, pcntl, standard, mysqlnd, PDO, pdo_mysql, pdo_sqlite, Phar, posix, random, Reflection, mysqli, shmop, SimpleXML, soap, sockets, sodium, sysvsem, tokenizer, xml, xmlreader, xmlwriter, cgi-fcgi, zip, fileinfo, redis, gmp, exif, Zend OPcache
+----------------------------------------+------------+------------------------------------------+---------------------------------------+
| Flarum Extensions                      |            |                                          |                                       |
+----------------------------------------+------------+------------------------------------------+---------------------------------------+
| ID                                     | Version    | Commit                                   | Notes                                 |
+----------------------------------------+------------+------------------------------------------+---------------------------------------+
| flarum-tags                            | v1.8.6     |                                          |                                       |
| flarum-suspend                         | v1.8.1     |                                          |                                       |
| flarum-mentions                        | v1.8.2     |                                          |                                       |
| flarum-subscriptions                   | v1.8.0     |                                          |                                       |
| fof-user-directory                     | 1.3.2      |                                          |                                       |
| fof-follow-tags                        | 1.2.9      | decbaad1974fa82db2118808bc5cf4606c5a4603 |                                       |
| fof-pages                              | 1.0.7      |                                          |                                       |
| askvortsov-auto-moderator              | v0.1.3     |                                          | Replaced by askvortsov/flarum-automod |
| flarum-likes                           | v1.8.1     |                                          |                                       |
| flarum-bbcode                          | v1.8.0     |                                          |                                       |
| fof-upload                             | 1.4.2      | a3fd04673555bd2b3e203ba2829b351988d9e5d5 |                                       |
| flarum-sticky                          | v1.8.0     |                                          |                                       |
| fof-merge-discussions                  | 1.4.1      |                                          |                                       |
| flarum-nicknames                       | v1.8.3     |                                          |                                       |
| fof-best-answer                        | 1.3.2      |                                          |                                       |
| fof-sitemap                            | 2.2.1      |                                          |                                       |
| flarum-markdown                        | v1.8.0     |                                          |                                       |
| fof-forum-widgets-core                 | 1.0.0      |                                          |                                       |
| flamarkt-backoffice                    | 0.1.3      | fcc600515e49ffc1000be26d2cc55974de63dedc |                                       |
| flarum-flags                           | v1.8.0     |                                          |                                       |
| flarum-lock                            | v1.8.0     |                                          |                                       |
| antoinefr-money                        | v1.3.1     |                                          |                                       |
| zerosonesfun-bbcode-audio              | 3.1.3      | 7747545af60c6ebc2e9a775258da9ba1bcefd3b7 | Deprecated                            |
| zequeen-acgembed-remastered            | v1.1.2     | 223fc0f61c3514274eddc39e2ba7d43a1ba33c1e |                                       |
| v17development-user-badges             | v1.1.0     |                                          |                                       |
| the-turk-stickiest                     | 3.0.1      |                                          |                                       |
| sycho-profile-cover                    | v1.3.5     |                                          |                                       |
| pipecraft-id-slug                      | v1.1.0     |                                          |                                       |
| nyu8-email-filter                      | 1.0.7      | d47b489433168762711f8433e753112b0a8e93aa |                                       |
| nearata-embed-video                    | 3.3.2      |                                          |                                       |
| michaelbelgium-discussion-views        | v7.4.2     | aa024d1701c1e62d467e592d932f149ffe6b7918 |                                       |
| justoverclock-staff-members-widget     | 0.1.3      |                                          |                                       |
| justoverclock-guestengagement          | 1.0.3      |                                          |                                       |
| imeepo-daily-check-in                  | v1.1.0     |                                          |                                       |
| ianm-syndication                       | 1.3.5      |                                          |                                       |
| ianm-html-head                         | 1.2.3      | a67a4d08ad4c48e3733681ea72fe5b953bd66a4f |                                       |
| fof-username-request                   | 1.2.3      |                                          |                                       |
| fof-user-bio                           | 1.3.0      |                                          |                                       |
| fof-terms                              | 1.5.0      |                                          |                                       |
| fof-synopsis                           | 1.0.1      | ff697faa80828462bc39002236873feb07e24e11 |                                       |
| fof-split                              | 1.1.0      |                                          |                                       |
| fof-seo                                | 3.0.6      | 7adf3bbb89e02352a55080a1394c64393e5295f4 |                                       |
| fof-rich-text                          | 1.0.0      | b117224e91c1222bfe28a7030b792a6a17576853 |                                       |
| fof-profile-image-crop                 | 1.1.6      |                                          |                                       |
| fof-prevent-necrobumping               | 1.2.1      |                                          |                                       |
| fof-polls                              | 2.2.14     | ba8ef44355e0a24c0269dc763bd12f4e90c60b82 |                                       |
| fof-online-users-widget                | 1.0.0      |                                          |                                       |
| fof-nightmode                          | 1.5.3      |                                          |                                       |
| fof-news-widget                        | 1.0.0      |                                          |                                       |
| fof-links                              | 1.2.0      |                                          |                                       |
| fof-linguist                           | 1.1.1      |                                          |                                       |
| fof-impersonate                        | 1.1.1      |                                          |                                       |
| fof-html-errors                        | 1.1.1      |                                          |                                       |
| fof-forum-stats-widget                 | 1.0.1      |                                          |                                       |
| fof-formatting                         | 1.0.3      |                                          |                                       |
| fof-drafts                             | 1.2.14     | 7b57aab073775f66c850b88fd51e7ca558ab5023 |                                       |
| fof-doorman                            | 2.0.0      |                                          |                                       |
| fof-direct-links                       | 1.0.1      | 6eed7687e3e3b85dbdc8d4a6e9d2903ecea4b388 |                                       |
| fof-clockwork                          | 1.1.1      | 8cd15386dedc8a7a72f3890270b0afc410e7bdf5 |                                       |
| fof-anti-spam                          | 1.1.4      | bdde035f45c704dd3dbf9f2ee6abf6e37da09dad |                                       |
| flarum-statistics                      | v1.8.0     |                                          |                                       |
| flarum-lang-english                    | v1.8.0     |                                          |                                       |
| flarum-lang-chinese-simplified         | v1.3.0     |                                          |                                       |
| flarum-audit                           | v1.8.0     | 1c7c3a9f0cedbbbb6bb3e95366958c811ff217a7 |                                       |
| edgeinfinity-auto-lang                 | dev-master | e720387db6054910d20afcc8036ca4fc3776b8d7 |                                       |
| ecnu-im-sticky-sidenav                 | v1.1.0     |                                          |                                       |
| club-1-cross-references                | v1.1.1     | dd7f359455791c93a7e4e5283c998dd046720dde |                                       |
| club-1-chore-commands                  | v1.0.0     | 94be946f33ddfcb03772939d461761fc1159abf1 |                                       |
| clarkwinkelmann-prominent-post-numbers | 1.0.1      |                                          |                                       |
| clarkwinkelmann-post-stream-search     | 1.1.0      | 673fa9d19ff5e79f6629d78abc885cd531968243 |                                       |
| clarkwinkelmann-money-rewards          | 1.0.0      | 998f9253cd67cc60872e03b40b8a27a07e8ece89 |                                       |
| clarkwinkelmann-mailing                | 1.1.0      |                                          |                                       |
| clarkwinkelmann-emojionearea           | 1.0.0      |                                          |                                       |
| blomstra-sort-order-toggle             | 0.2.0      | 4e3cf5919fa2af5e09594eefebfb4506d6c330dc |                                       |
| blomstra-search                        | 0.1.19     | cf1b56e900d1a4dd6aedbd00898fe1f1f5335b00 |                                       |
| blomstra-realtime                      | 0.3.2      | 832f23c56711e25de6215beb45663c260a540c6e |                                       |
| askvortsov-pwa                         | v3.4.1     | d1e14b417ba6c39cead7ecf39affba28201e04f8 |                                       |
| askvortsov-moderator-warnings          | v0.6.3     |                                          |                                       |
| askvortsov-markdown-tables             | v1.2.1     |                                          |                                       |
| askvortsov-categories                  | v3.0.9     |                                          |                                       |
| acpl-mobile-tab                        | 1.4.1      |                                          |                                       |
+----------------------------------------+------------+------------------------------------------+---------------------------------------+
Base URL: https://forum.monika.love
Installation path: /www/wwwroot/192.168.5.132/public
Queue driver: redis
Session driver: redis (Code override. Configured to file)
Scheduler status: Active
Mail driver: smtp
Debug mode: off

@imorland imorland changed the title Fixed users page crashes using PHP 8.2+ [1.x] Fixed users page crashes using PHP 8.2+ Jul 28, 2026
@imorland

imorland commented Aug 3, 2026

Copy link
Copy Markdown
Member

We do advise to run Flarum 1.x on PHP 8.2+ with deprecations suppressed. The old underlying stack has code we cannot update... This would immediately resolve your problem here.

That said, this fix is within our control, so potentially we could merge this. Thinking....

Coalesce a null `q` to an empty string in AbstractSearcher::search()
rather than in GambitManager::explode(), where the `string` parameter
type makes `?? ''` dead code that fails PHPStan. This keeps the gambit
chain's type contract intact and also covers an empty/absent `q`.

Adds a regression test asserting a null search query does not emit the
str_getcsv() null deprecation (fatal on strict PHP 8.1+ setups).
The error handler threw on any E_DEPRECATED emitted during the request,
so it was derailed by unrelated framework deprecations on PHP 8.4.
Narrow it to the str_getcsv deprecation under test.
PHP 8.5 separately deprecates str_getcsv()'s default $escape argument,
which fires on every call regardless of this fix. Match the "Passing
null" message specifically so the regression test guards only the null
query it covers.
@imorland imorland changed the title [1.x] Fixed users page crashes using PHP 8.2+ [1.x] fix(search): coalesce null query before gambits to avoid str_getcsv deprecation Aug 3, 2026
@imorland

imorland commented Aug 3, 2026

Copy link
Copy Markdown
Member

Thanks for this @edgeinfinity1 — the bug is real. I've pushed a few commits under the maintainer-edit permission to get it merge-ready:

  • Moved the fix from GambitManager::explode() to the caller in AbstractSearcher::search() ($criteria->query['q'] ?? ''). PHPStan rejected the original spot because explode()'s parameter is typed string, so ?? '' there was dead code. Coalescing at the caller — where the null actually originates — keeps the gambit chain's type contract intact and also covers an empty/absent q.
  • Added a regression test that fails on the str_getcsv null deprecation without the fix.
  • Narrowed the test's error handler to the "Passing null" message specifically, so it isn't derailed by unrelated framework deprecations (PHP 8.4) or PHP 8.5's separate deprecation of str_getcsv()'s default $escape argument.

GambitManager is back to its original state, and CI is green across the matrix. I've retitled the PR to reflect the final change.

@imorland imorland added this to the 1.8.18 milestone Aug 3, 2026
@imorland
imorland merged commit e1fa1ea into flarum:1.x Aug 3, 2026
427 of 456 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants