FriendsOfFlarum / user-directory

The permission based public user directory extension for your Flarum forum.
https://discuss.flarum.org/d/5682
MIT License
22 stars 18 forks source link

explode() string expected, array given on /users #29

Closed clarkwinkelmann closed 5 years ago

clarkwinkelmann commented 5 years ago

If PHP Warnings are not hidden, the following appears when accessing /users directly:

Warning: explode() expects parameter 2 to be string, array given in /var/www/vhosts/domain.com/forum.domain.com/vendor/tobscure/json-api/src/Parameters.php on line 124

Warning: Invalid argument supplied for foreach() in /var/www/vhosts/domain.com/forum.domain.com/vendor/tobscure/json-api/src/Parameters.php on line 126

Fatal error: Uncaught Zend\HttpHandlerRunner\Exception\EmitterException: Output has been emitted previously; cannot emit response in /var/www/vhosts/domain.com/forum.domain.com/vendor/zendframework/zend-httphandlerrunner/src/Exception/EmitterException.php:23 Stack trace: #0 /var/www/vhosts/domain.com/forum.domain.com/vendor/zendframework/zend-httphandlerrunner/src/Emitter/SapiEmitterTrait.php(39): Zend\HttpHandlerRunner\Exception\EmitterException::forOutputSent() #1 /var/www/vhosts/domain.com/forum.domain.com/vendor/zendframework/zend-httphandlerrunner/src/Emitter/SapiEmitter.php(26): Zend\HttpHandlerRunner\Emitter\SapiEmitter->assertNoPreviousOutput() #2 /var/www/vhosts/domain.com/forum.domain.com/vendor/zendframework/zend-httphandlerrunner/src/RequestHandlerRunner.php(97): Zend\HttpHandlerRunner\Emitter\SapiEmitter->emit(Object(Zend\Diactoros\Response\HtmlResponse)) #3 /var/www/vhosts/domain.com/forum.domain.com/vendor/flarum/core/src/Http/Server.php(46): Zend\HttpHandle in /var/www/vhosts/domain.com/forum.domain.com/vendor/zendframework/zend-httphandlerrunner/src/Exception/EmitterException.php on line 23

No idea if we're doing something wrong in User Directory, or if it's an issue in the JSON API library...

If someone has time to dig into the root cause, all help is welcome :smile:

The workaround is to hide the PHP Warnings in the page output, as it should be on production anyway.

kristjanoja commented 5 years ago

I am not 100% sure but it seems that the issue is here: fof/user-directory/src/Content/UserDirectory.php on line 65 'sort' => array_get($this->sortMap, $sort, ''), when $sort is NULL eg you open /users and there is no sort parameter, the array_get returns the whole array of sortMap and not the default value I have fixed this by adding default value to $sort variable if it is missing on line 60 $sort = array_pull($queryParams, 'sort'); <- old line $sort = array_pull($queryParams, 'sort') ?? 'username'; <- new line

clarkwinkelmann commented 5 years ago

@stream0 thank you very much, this was indeed the issue :+1: