Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cmanley opened this issue Jul 18, 2020 · 2 comments · May be fixed by #11
Open

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

cmanley opened this issue Jul 18, 2020 · 2 comments · May be fixed by #11

Comments

@cmanley
Copy link

cmanley commented Jul 18, 2020

Here it is:

$this->throwHttpExceptionOnHttpError($http_response_header);

and a few lines down too.
That gets converted into an ErrorException in onError() so the proper send() HTTP exception handling is effectively bypassed.

@theroch theroch linked a pull request Mar 8, 2021 that will close this issue
@cmanley
Copy link
Author

cmanley commented Mar 27, 2021

More info:

See:

$this->throwHttpExceptionOnHttpError($http_response_header);

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

@pfeigl
Copy link

pfeigl commented May 19, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants