elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
5.27k stars 965 forks source link

Declaration of Elastic\Elasticsearch\Response\Elasticsearch::withStatus(int $code, string $reasonPhrase = ''): Psr\Http\Message\ResponseInterface must be compatible with PsrExt\Http\Message\ResponseInterface::withStatus($code, $reasonPhrase = <default>) #1327

Closed ccc-nghia-le closed 1 year ago

ccc-nghia-le commented 1 year ago

Summary of problem or feature request

I created a deployment in elasticloud, and set up the connection. Then I performed a search using $client->search() surrounded it with a try catch code block, via debugging I could it failed with http code 401 Unauthorised, I believe there is something wrong with my elasticloud setup, that's fine. I expected it would hit my catch() block but it never did. Instead there was an error thrown:

Declaration of Elastic\Elasticsearch\Response\Elasticsearch::withStatus(int $code, string $reasonPhrase = ''): Psr\Http\Message\ResponseInterface must be compatible with PsrExt\Http\Message\ResponseInterface::withStatus($code, $reasonPhrase = <default>)

Code snippet of problem

$client = Elastic\Elasticsearch\ClientBuilder::create() ->setElasticCloudId('') ->setApiKey('') ->build();

try { $result = $client->search($params); } catch (\Exception $e) { dd(' It should hit here but it did not'); }

System details

danielsimkus commented 1 year ago

I got this too. Had to do composer require elasticsearch/elasticsearch:8.8.0 to get it working, something about allowing psr/http-message: ^2 is causing issues from 8.8.1

ccc-nghia-le commented 1 year ago

I got this too. Had to do composer require elasticsearch/elasticsearch:8.8.0 to get it working, something about allowing psr/http-message: ^2 is causing issues from 8.8.1

Downgrading to 8.8.0 did actually help. Thank you very much !

I hope they will fix this soon in a future release.

murilolivorato commented 1 year ago

thanks a lot, its worked for me as well .

ezimuel commented 1 year ago

@murilolivorato, @ccc-nghia-le and @danielsimkus can you try the PR #1344 and let me know if this fix the issue? Thanks!

ezimuel commented 1 year ago

I finally reproduced the issue, read here: https://github.com/elastic/elasticsearch-php/issues/1342#issuecomment-1663517415

ezimuel commented 1 year ago

The discussion will continue in #1342. If you still have issue please test this solution.