Skip to content

[MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set #49392

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

Closed
simonberger opened this issue Feb 15, 2023 · 2 comments

Comments

@simonberger
Copy link
Contributor

Symfony version(s) affected

5.4.20 and above

Description

When no user agent is set FirePHPHandler::onKernelResponse throws

Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated

in PHP 8.1 and above

https://github.com/symfony/symfony/blob/5.4/src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php#L44

How to reproduce

I have no reproducer but it is an obvious potential problem because HeaderBag::get is allowed to return null.

Possible Solution

No response

Additional Context

No response

@stof
Copy link
Member

stof commented Feb 15, 2023

The condition should be updated to handle the case of not having a user agent. Do you want to send a PR ?

@simonberger
Copy link
Contributor Author

No, anyone can pick up. This is an easy first PR.

nicolas-grekas added a commit that referenced this issue Feb 21, 2023
…P 8.1 deprecation when no user agent is set (juagarc4)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set

| Q             | A
| ------------- | ---
| Branch?       |  5.4
| Bug fix?      | yes/no
| New feature?  no
| Deprecations? no
| Tickets       | Fix #49392
| License       | MIT

- Add casting to the second parameter to pass always the right type.

**PHPstan before:**

 ------ --------------------------------------------------------------------------------------------------------
  Line   FirePHPHandler.php
 ------ --------------------------------------------------------------------------------------------------------
  27     Property Symfony\Bridge\Monolog\Handler\FirePHPHandler::$headers has no type specified.
  37     Method Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse() has no return type specified.
  **44     Parameter #2 $subject of function preg_match expects string, string|null given.**
  68     If condition is always true.
 ------ --------------------------------------------------------------------------------------------------------

**PHPstan after:**

 ------ --------------------------------------------------------------------------------------------------------
  Line   FirePHPHandler.php
 ------ --------------------------------------------------------------------------------------------------------
  27     Property Symfony\Bridge\Monolog\Handler\FirePHPHandler::$headers has no type specified.
  37     Method Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse() has no return type specified.
  68     If condition is always true.
 ------ --------------------------------------------------------------------------------------------------------

Commits
-------

4d84c46 [MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants