php-http / documentation

Documentation for PHP-HTTP including HTTPlug
http://docs.php-http.org
MIT License
23 stars 56 forks source link

Class *** Not Found issue in php-http/discovery #296

Closed ShinJii89 closed 2 years ago

ShinJii89 commented 2 years ago

PHP version: 8.0.19 (but it also happened on 7.4.x)

Description After installation of composer require mailerlite/mailerlite-api-v2-php-sdk (0.3.2, in 0.2.3 it's working fine [because they are using older version of php-http in 0.2.3]) I'm getting errors from php-http/discovery... that errors are just displaying as strings in my script (like echo)... not fatal errors/warnings in php level... Some more informations here (like my composer.json, composer.lock): https://github.com/mailerlite/mailerlite-api-v2-php-sdk/issues/50

If I'm not use any HTTP CLIENT in their RestClient then their code do this:

if (is_null($this->httpClient)) {
            $this->httpClient = Psr18ClientDiscovery::find();
        }

        return $this->httpClient;

And then my script shows me Class Phalcon/Http/Message/RequestFactory not foundClass Phalcon/Http/Message/RequestFactory not foundClass Symfony/Component/HttpClient/HttplugClient not foundClass Http/Adapter/Guzzle7/Client not foundClass Http/Adapter/Guzzle6/Client not foundClass Http/Adapter/Guzzle5/Client not foundClass Http/Client/Socket/Client not foundClass Http/Adapter/Buzz/Client not foundClass Http/Adapter/React/Client not foundClass Http/Adapter/Cake/Client not foundClass Http/Adapter/Zend/Client not foundClass Http/Adapter/Artax/Client not foundClass Symfony/Component/HttpClient/Psr18Client not foundClass Symfony/Component/HttpClient/Psr18Client not foundClass Symfony/Component/HttpClient/Psr18Client not foundClass Buzz/Client/FileGetContents not foundClass Buzz/Client/FileGetContents not foundClass Buzz/Client/FileGetContents not foundClass Phalcon/Http/Message/ResponseFactory not foundClass Phalcon/Http/Message/ResponseFactory not foundClass Phalcon/Http/Message/StreamFactory not foundClass Phalcon/Http/Message/StreamFactory not found

But when I change their code of HTTP CLIENT to something like

if (is_null($this->httpClient)) {
            $options = [
                CURLOPT_CONNECTTIMEOUT => 10,
                CURLOPT_SSL_VERIFYPEER => false
            ];

            $this->httpClient = new CurlClient(Psr17FactoryDiscovery::findResponseFactory(), Psr17FactoryDiscovery::findStreamFactory(), $options);
        }

        return $this->httpClient;

my script shows just: Class Phalcon/Http/Message/RequestFactory not foundClass Phalcon/Http/Message/RequestFactory not foundClass Phalcon/Http/Message/ResponseFactory not foundClass Phalcon/Http/Message/ResponseFactory not foundClass Phalcon/Http/Message/StreamFactory not foundClass Phalcon/Http/Message/StreamFactory not found

QUESTION IS WHY? Why it's showing something like that if i'm not using that http client? And it happens only if I install their newest version of library (I can install many other libraries and something like that just not happening)...but I checked their code and I don't see anything wrong... I guess it's your fault but why?

How to reproduce I don't know, maybe install their library

Possible Solution

Additional context

ShinJii89 commented 2 years ago

Screenshot 2022-05-20 at 15-32-56 Panel Administracyjny - Integracje źródło wiedzy It looks like in attachment.... as you can see errors appear but script is doing what should do... lists from mailerlite are downloaded....

dbu commented 2 years ago

i tried to cleanup the requirements in https://github.com/mailerlite/mailerlite-api-v2-php-sdk/pull/63 after that it should be possible to require guzzlehttp/guzzle and have everything you need.

but i actually think that with the setup you currently seem to have, things should work out and discovery should find the implementations.

i don't know what is doing the printing of class names. the discovery checks for existence of those classes, but usually that does not produce output. you can check if class_exists(Foo::class); added to your code produces any output. it should not. if it does, it would be a misconfiguration of PHP, or a strange thing in your autoloader.

ShinJii89 commented 2 years ago

i tried to cleanup the requirements in mailerlite/mailerlite-api-v2-php-sdk#63 after that it should be possible to require guzzlehttp/guzzle and have everything you need.

but i actually think that with the setup you currently seem to have, things should work out and discovery should find the implementations.

i don't know what is doing the printing of class names. the discovery checks for existence of those classes, but usually that does not produce output. you can check if class_exists(Foo::class); added to your code produces any output. it should not. if it does, it would be a misconfiguration of PHP, or a strange thing in your autoloader.

oh sh*t.... thanks for your reply... it's really something in my autoloader code lol I didn't know it can interrupt somehow composer lol... great xD now it's fixed thanks!!!!

dbu commented 2 years ago

glad you found where it comes from, and thanks for reporting back and closing the issue.