InvalidArgumentException thrown with message "Passed variable is not an array or object"
Stacktrace:
#21 InvalidArgumentException in /path/to/plugins/typerocket-pro-v5/typerocket/vendor/typerocket/core/src/Http/Fields.php:36
#20 ArrayObject:exchangeArray in /path/to/plugins/typerocket-pro-v5/typerocket/vendor/typerocket/core/src/Http/Fields.php:36
#19 TypeRocket\Http\Fields:__construct in [internal]:0
#18 ReflectionClass:newInstanceArgs in /path/to/plugins/typerocket-pro-v5/typerocket/vendor/typerocket/core/src/Core/Resolver.php:34
#17 TypeRocket\Core\Resolver:resolve in /path/to/plugins/typerocket-pro-v5/typerocket/vendor/typerocket/core/src/Core/Resolver.php:109
#16 TypeRocket\Core\Resolver:getDependencies in /path/to/plugins/typerocket-pro-v5/typerocket/vendor/typerocket/core/src/Core/Resolver.php:71
Steps to reproduce
Create a HTTP Fields class. It does not have to provide any "fillable" fields.
Create a controller and use the newly created fields class as parameter to an action, so it will be dependency injected.
Send a GET request for example, with no fields added.
The HTTP Fields might throw an exception if a request has no fields. That might be the case where these fields are optional.
Analysis
This exception is caused due to how the
Fields
constructor is written. During internal request processing by TypeRocket, an empty array (of arguments) is passed to theFields
class. In that case, theFields
class obtains the fields from the currentrequest
. Since there are none, the request returnsnull
. Later,null
is passed to PHP's built-inArrayObject::exchangeArray()
, which causes the exception.Exception trace:
Steps to reproduce
GET
request for example, with no fields added.