Bug #101764
closedInvalid type check for resource in \TYPO3\CMS\Core\Http\Request
100%
Description
The constructor of the Request class is supposed to accept a $body of the type "string|resource|StreamInterface|null". However, it does not accept a "resource" because it tests for the wrong string from `get_debug_type($body)`.
$this->body = match (get_debug_type($body)) {
'string', 'resource' => new Stream($body),
'null' => null,
default => throw new \InvalidArgumentException('Body must be a string stream resource identifier, a stream resource, or a StreamInterface instance', 1436717271),
};
According to the PHP documentation `get_debug_type()` will never return just the string "resource". It will instead return "resource (resourcename)" (e.g. "resource (stream)") or "resource (closed)". https://www.php.net/manual/en/function.get-debug-type.php#refsect1-function.get-debug-type-returnvalues
Since the returned string changes depending on the type of resource, it is not possible to predict exactly. This means `get_debug_type()` and `match` cannot be used to test for a resource, as `match` relies on an exact string.
The implementation in TYPO3 v11 works correctly. It is implemented a bit different, but correctly uses `is_resource($body)`.