php-http/HttplugBundle

Collector not compatible with Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface

tinwe123 opened this issue · 9 comments

PHP version: 7.1.33

Description
During composer install then clearing cache in symfony application i got fatal error

How to reproduce

Possible Solution
public function collect(Request $request, Response $response, \Exception $exception = null)
instead
public function collect(Request $request, Response $response, $exception = null)

PHP Fatal error: Declaration of Http\HttplugBundle\Collector\Collector::collect(Symfony\Component\HttpFoundation\R
equest $request, Symfony\Component\HttpFoundation\Response $response, $exception = NULL) must be compatible with Sy
mfony\Component\HttpKernel\DataCollector\DataCollectorInterface::collect(Symfony\Component\HttpFoundation\Request $
request, Symfony\Component\HttpFoundation\Response $response, ?Exception $exception = NULL) in /vendor/php-http/httplug-bundle/src/Collector/Collector.php on line 191

Which version of the bundle do you use? 1.1.6.0 is the latest version supporting PHP 7.1 and the code looks different there.

I double this: I get incompatibility fatal error.
Relevant composer.json parts:

{
"require": {
    "php": ">=7.1",
    "symfony/symfony": "^3.4",
    "php-http/guzzle6-adapter": "^2.0",
    "php-http/httplug-bundle": "^1.18"
}
}

Symfony 3.4.43 with httplug 2.2.0 and httplug-bundle 1.18 installed.
The reason is that \Http\HttplugBundle\Collector\Collector::collect does not define the last $exception parameter to be of type ?Exception

Works fine on 1.17.0

Which PHP version do you use when you run into this issue?

lies commented

I have some problem.
Symfony 3.4
httplug-bundle 1.18
php 7.2

dbu commented

in #387 i make the lowest version test with php 7.2. the test is green with 7.2, so either we are missing a test on that collector or something weird is going on.

we do test the collector: https://github.com/php-http/HttplugBundle/blob/master/tests/Unit/Collector/CollectorTest.php

why does this not fail during the tests?

@lies Are you sure that this is happening on PHP 7.2? Please note that the PHP version used on the command-line may be different from the one used when serving your application over HTTP.

Problem confirmed here.

PHP 7.1.33, but composer config.platform.php is PHP 7.2.5.
Symfony 3.4.5 (problematic file)
HttplugBundle 1.19.0 (problematic file)

I can confirm also that the bug appeared in 1.18.0.

Well, If you are running your application on PHP 7.1, you must not set the platform PHP version to 7.2 as you will get non-compatible dependencies then.

dbu commented

if you hack around with the platform configuration, i recommend you set your requirements, as well as indirect requirements, to exact version numbers that you know work together. (e.g. find in the httplug bundle changelog where we drop support for php 7.1 and pin your requirement to php-http/httplug-bundle to the version that came right before that).