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

Function signature regression for ob_start with PHP 8.1? #7522

Open
mind-bending-forks opened this issue Jun 23, 2022 · 2 comments · May be fixed by phpstan/phpstan-src#3586
Open

Function signature regression for ob_start with PHP 8.1? #7522

mind-bending-forks opened this issue Jun 23, 2022 · 2 comments · May be fixed by phpstan/phpstan-src#3586
Labels
Milestone

Comments

@mind-bending-forks
Copy link

Issue

PHPStan has started complaining for PHP 8.x when the first argument to ob_start ($callback) is null. See https://phpstan.org/r/1164573f-22b3-41fd-a678-bdd27058615b It reports:

Parameter #1 $callback of function ob_start expects callable(): mixed, null given.

However, the documentation for ob_start on 23 June 2022 has:

  • a function signature with the first argument accepting null,
  • text that says that "The callback parameter may be bypassed by passing a null value"; and
  • an example with null as the first argument.

So, unless the documentation is out of date, this looks to be a regression in the ob_start function signature, most likely relating to changes in the way callables are handled in PHP 8.x.

Reproducing

Use the second example from the ob_start documentation, a one-liner:

ob_start(null, 0, PHP_OUTPUT_HANDLER_STDFLAGS ^ PHP_OUTPUT_HANDLER_REMOVABLE);

Implemented at https://phpstan.org/r/1164573f-22b3-41fd-a678-bdd27058615b

Expected output: PHPStan should not report any errors.

Other

We're working on PHP 8.x support for our PHP code base. PHPStan is proving to be a valuable tool. Not sure how we managed to get by without it before. Thanks.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jun 23, 2022
@ondrejmirtes
Copy link
Member

This is how the ob_start stub looks like: https://github.com/phpstan/php-8-stubs/blob/main/stubs/ext/standard/ob_start.php

This piece of code needs to be adjusted to add null if there's a = null default value next to the parameter: https://github.com/phpstan/phpstan-src/blob/9496feba014a0b26ab4c0b252a225a4b3aee0692/src/Reflection/SignatureMap/Php8SignatureMapProvider.php#L328-L348

@phpstan-bot
Copy link
Contributor

@mind-bending-forks After the latest push in 1.12.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 – 8.1 (1 error)
+PHP 8.4
+==========
+
+No errors
+
+PHP 8.0 – 8.3 (1 error)
 ==========
 
 4: Parameter #1 $callback of function ob_start expects callable(): mixed, null given.
Full report

PHP 8.4

No errors

PHP 8.0 – 8.3 (1 error)

Line Error
4 Parameter #1 $callback of function ob_start expects callable(): mixed, null given.

PHP 7.1 – 7.4

No errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants