PHP Fatal error on the MultipartStream with PumpStream instance
TheNorthMemory opened this issue · comments
James ZHANG commented
PHP version: 7.4.24
Description
Here's a case about the MultipartStream
usage. If I want to compose the multipart instance with the PumpStream
instance, A PHP Fatal error on there. The problem maybe on the following line:
https://github.com/guzzle/psr7/blob/master/src/MultipartStream.php#L92
PHP Fatal error: Uncaught TypeError: substr() expects parameter 1 to be string, null given in /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php:92
Stack trace:
#0 /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php(92): substr(NULL, 0, 6)
#1 /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php(71): GuzzleHttp\Psr7\MultipartStream->addElement(Object(GuzzleHttp\Psr7\AppendStream), Array)
#2 /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php(35): GuzzleHttp\Psr7\MultipartStream->createStream(Array)
#3 /dummytest/test-multipart.php(17): GuzzleHttp\Psr7\MultipartStream->__construct(Array)
#4 {main}
thrown in /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php on line 92
Fatal error: Uncaught TypeError: substr() expects parameter 1 to be string, null given in /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php:92
Stack trace:
#0 /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php(92): substr(NULL, 0, 6)
#1 /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php(71): GuzzleHttp\Psr7\MultipartStream->addElement(Object(GuzzleHttp\Psr7\AppendStream), Array)
#2 /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php(35): GuzzleHttp\Psr7\MultipartStream->createStream(Array)
#3 /dummytest/test-multipart.php(17): GuzzleHttp\Psr7\MultipartStream->__construct(Array)
#4 {main}
thrown in /dummytest/vendor/guzzlehttp/psr7/src/MultipartStream.php on line 92
How to reproduce
<?php
require_once('./vendor/autoload.php');
use GuzzleHttp\Psr7\Utils;
use GuzzleHttp\Psr7\MultipartStream;
$buf1 = Utils::streamFor('dummy text1.');
$buf2 = Utils::streamFor(static function() { return 'dummy text2.'; });
$stream = new MultipartStream([
[
'name' => 'test1',
'contents' => $buf1,
],
[
'name' => 'test2',
'contents' => $buf2,
],
]);
print_r($stream);
Possible Solution
The getMetadata
method should returns null
while there wasn't the uri
meta data available.
On L92, here should be checked that the $uri
is Truthy
then call substr
function.