Skip to content

feat: add support for Guzzle 8 #9377

Open
GrahamCampbell wants to merge 1 commit into
googleapis:mainfrom
GrahamCampbell:guzzle-8
Open

feat: add support for Guzzle 8 #9377
GrahamCampbell wants to merge 1 commit into
googleapis:mainfrom
GrahamCampbell:guzzle-8

Conversation

@GrahamCampbell

Copy link
Copy Markdown
Contributor

Guzzle 8.0.0 was released on July 20th. Lots of people want to use it, and thus popular packages in the ecosystem like this one need to be updated to support it, so here I am, adding support. :)

Comment thread Gax/phpstan.neon.dist Outdated
Comment thread Gax/src/ApiException.php
@GrahamCampbell
GrahamCampbell force-pushed the guzzle-8 branch 2 times, most recently from e9b14c3 to 406ea4c Compare July 22, 2026 00:00
@GrahamCampbell
GrahamCampbell marked this pull request as ready for review July 22, 2026 23:22
Comment on lines +217 to +219
function ($line) {
return strpos($line, 'Content-Length:') !== 0;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
function ($line) {
return strpos($line, 'Content-Length:') !== 0;
}
fn ($line) => strpos($line, 'Content-Length:') !== 0;

Comment thread Gax/src/ApiException.php
// Guzzle 7 carries the response on RequestException, Guzzle 8 only on
// its ResponseException subclass, hence the method_exists() check.
$res = method_exists($ex, 'getResponse') ? $ex->getResponse() : null;
$body = (string) $res->getBody();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this instance, we would get a PHP fatal error ("Call to a member function getBody() on null") if the above exception does not have method getResponse. However, the current behavior is the same - if getResponse() returns null, the same PHP fatal error is thrown.

If I am understanding this correctly, EVERY instance in Guzzle 7 which returned a response for RequestException::getResponse() now returns a ResponseException in Guzzle 8, is that accurate? If so this should be safe, and any changes to this behavior would be a separate bug fix.

Even so it might be a good idea to protect from fatal errors like this, and to add a comment in the method description that the method expects either a RequestException with a response in Guzzle 7, or a ResponseException in Guzzle 8.

Suggested change
$body = (string) $res->getBody();
$body = (string) $res?->getBody();

@bshaffer bshaffer added the next release PRs to be included in the next release label Jul 24, 2026

@Hectorhammett Hectorhammett left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thank you so much @GrahamCampbell For this contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

next release PRs to be included in the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants