Skip to content
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

Incorrect Dependency Declaration of psr/http-message leads to Fatal Error #1318

Closed
MaxBoeh opened this issue May 27, 2023 · 6 comments
Closed

Comments

@MaxBoeh
Copy link

MaxBoeh commented May 27, 2023

Summary of problem or feature request

The version constraint of dependency

"psr/http-message": "^1.0 || ^2.0"

is not correct, as for version 1 \Psr\Http\Message\ResponseInterface::withStatus looks like this:

    public function withStatus(int $code, string $reasonPhrase = '');

While the implementation in \Elastic\Elasticsearch\Traits\MessageResponseTrait::withStatus looks like this:

    public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface

Leading to this fatal error:

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

Please remove v1 of psr/http-message from the version constraint.

System details

  • PHP Version: 8.0
  • ES-PHP: 8.8.1
@ezimuel
Copy link
Contributor

ezimuel commented Jun 5, 2023

@MaxBoeh I just checked using v1 of psr/http-message and the latest Elasticsearch response implementation and it works thanks to the Covariant Returns and Contravariant Parameters of PHP from 7.4+.
Can you check please:

  • if you are using PHP 8.0.0+
  • if you executed composer update
  • what's the output of composer info regarding the psr/http-message and elasticsearch/elasticsearch?

Thanks.

@ChrisTitos
Copy link

I ran into this just now, and it turns out we were using psr/http-message version 1.0.1, but it only worked using version 1.1, where they added typehints to parameters

@ezimuel
Copy link
Contributor

ezimuel commented Jun 5, 2023

I had to remove the tag v8.8.1 because it has been released before the official schedule. The tag v8.8.1 will be re-created soon in a few days. Sorry for any inconvenience

@MaxBoeh
Copy link
Author

MaxBoeh commented Jun 6, 2023

I just checked out the branch where I had the issue, tried it again, same php version, same composer.lock and it just works. I'm a bit baffled. I'm kind of glad others experienced the same issue 😅

I'm on psr/http-message 1.1, with elasticsearch/elasticsearch 8.8.1 and also tried 8.8.0

composer info psr/http-message

name : psr/http-message
descrip. : Common interface for HTTP messages
keywords : http, http-message, psr, psr-7, request, response
versions : * 1.1
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://github.com/php-fig/http-message
source : [git] https://github.com/php-fig/http-message.git cb6ce4845ce34a8ad9e68117c10ee90a29919eba
dist : [zip] https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba cb6ce4845ce34a8ad9e68117c10ee90a29919eba
path : /mnt/c/Users/maxbo/git-workspace/nerdkap/ecommerce-affiliates/vendor/psr/http-message
names : psr/http-message

support
source : https://github.com/php-fig/http-message/tree/1.1

autoload
psr-4
Psr\Http\Message\ => src/

requires
php ^7.2 || ^8.0

composer info elasticsearch/elasticsearch

name : elasticsearch/elasticsearch
descrip. : PHP Client for Elasticsearch
keywords : client, elastic, elasticsearch, search
versions : * v8.8.0
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage :
source : [git] git@github.com:elastic/elasticsearch-php.git 5c4d678
dist : [zip] https://api.github.com/repos/elastic/elasticsearch-php/zipball/5c4d67870b92fedc06fcceec5be8c3be8563fe3d 5c4d678
path : /mnt/c/Users/maxbo/git-workspace/nerdkap/ecommerce-affiliates/vendor/elasticsearch/elasticsearch
names : elasticsearch/elasticsearch

autoload
psr-4
Elastic\Elasticsearch\ => src/

requires
elastic/transport ^8.7
guzzlehttp/guzzle ^7.0
php ^7.4 || ^8.0
psr/http-client ^1.0
psr/http-message ^1.0
psr/log ^1|^2|^3

requires (dev)
ext-yaml *
ext-zip *
mockery/mockery ^1.5
nyholm/psr7 ^1.5
php-http/message-factory ^1.1
php-http/mock-client ^1.5
phpstan/phpstan ^1.4
phpunit/phpunit ^9.5
symfony/finder ~4.0
symfony/http-client ^5.0|^6.0

@ezimuel
Copy link
Contributor

ezimuel commented Jun 7, 2023

@MaxBoeh please use "elasticsearch/elasticsearch" : "=8.8.0" in your composer.json and run composer update. Let me know, thanks.

@MaxBoeh
Copy link
Author

MaxBoeh commented Jun 7, 2023

@ezimuel It works fine now. I have no idea what has changed on my end.

For me the issue can be closed, thank you for your support.

@ezimuel ezimuel closed this as completed Jun 9, 2023
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

No branches or pull requests

3 participants