Skip to content

Reproduce bug15813 - #7142

Closed
staabm wants to merge 2 commits into
phpstan:2.3.xfrom
staabm:bug15813
Closed

staabm wants to merge 2 commits into
phpstan:2.3.xfrom
staabm:bug15813

Conversation

@staabm

@staabm staabm commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The crash only happens when PHPStan itself runs on PHP 7.4, using the PHAR. A PHP 8.x runtime analyses the same file without errors.

  1. With phpVersion: 80400, round() has the PHP 8.4 signature, where $mode defaults to RoundingMode::HalfAwayFromZero. That's an enum without values.
  2. src/Reflection/BetterReflection/BetterReflectionProvider.php:163 only uses the enum adapter when PHP_VERSION_ID >= 80000. On 7.4 the enum gets the plain
    ReflectionClass adapter, so ClassReflection::isEnum() returns false.
  3. InitializerExprTypeResolver::getClassConstFetchTypeByReflection() then skips its enum-case branch and treats HalfAwayFromZero as a class constant. It calls
    getValueExpression() on an enum case that has no value, and BetterReflection throws "This enum case does not have a value".

The preg_replace/division in the reporter's snippet doesn't matter. Any round() call on 8.4 hits this, because PHPStan resolves the default values whenever it
looks up the function.

@staabm staabm closed this Nov 24, 2026
@staabm
staabm deleted the bug15813 branch November 24, 2026 17:05
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

Successfully merging this pull request may close these issues.

1 participant