php-json-rpc-http icon indicating copy to clipboard operation
php-json-rpc-http copied to clipboard

Bug: Undefined variable $http_response_header in Client->send()

Open cmanley opened this issue 5 years ago • 3 comments

Here it is: https://github.com/datto/php-json-rpc-http/blob/db15a075f3562c4e8d297b9082acc5b2869bd4b4/src/Client.php#L226 and a few lines down too. That gets converted into an ErrorException in onError() so the proper send() HTTP exception handling is effectively bypassed.

cmanley avatar Jul 18 '20 09:07 cmanley

More info:

See: https://github.com/datto/php-json-rpc-http/blob/db15a075f3562c4e8d297b9082acc5b2869bd4b4/src/Client.php#L229 and on line 226 too.

That triggered this exception in my code: ErrorException: Undefined variable: http_response_header at .../vendor/datto/json-rpc-http/src/Client.php line 229.

$http_response_header is a reserved variable, but it doesn't seem to always exist. See the note at the bottom of this page for the cause and solution: https://www.php.net/manual/en/reserved.variables.httpresponseheader.php Quoted below just in case it disappears in the future:

Bear in mind this special variable is somehow protected and not populated in some situation when the peer server close the connection early on (ssl reset) => Undefined variable: http_response_header

A code like this one: $response = @file_get_contents($url); empty($http_response_header) && $http_response_header = array('HTTP/1.1 400 Bad request');

Will return a cryptic error message: Fatal error: Call to undefined function array() on line 2

-- Should you want to cope with this situation: $hdrs = array('HTTP/1.1 400 Bad request'); !empty($htp_response_header) && $hdrs = $http_response_headers;

Now use $hdrs in place of $http_response_header

cmanley avatar Mar 27 '21 21:03 cmanley

We are seeing this same error when using https://github.com/fiskaly/fiskaly-sdk-php (which is based on this library).

While there is obviously a root problem which needs to be fixed, this makes it practically impossible to actually debug it, because all real error details are hidden from the surface

pfeigl avatar May 19 '21 15:05 pfeigl