Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Nov 25, 2025

No description provided.

assertType('string|false', ini_get('unknown'));

if (PHP_VERSION_ID >= 80500) {
assertType('string', ini_get("max_memory_limit"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works in type inference tests? 😱 Can you point to a piece of code that makes it work? We might want to refactor some tests thanks to this.

Copy link
Contributor Author

@staabm staabm Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it works because the constant PHP_VERSION_ID is narrowed via expressionTypes and these are taken into account in MutatingScope->getPhpVersion() via

$constType = $this->getGlobalConstantType(new Name('PHP_VERSION_ID'));

(it works as long as the relevant extensions utilize $scope->getPhpVersion() instead of a injected PhpVersion from the DIC)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense! I thought that TypeInferenceTestCase somehow skips the asserts if they are for a different PHP version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. this was a proof of concept that it actually works ;)

@ondrejmirtes ondrejmirtes merged commit 3e05142 into phpstan:2.1.x Nov 25, 2025
609 of 637 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the meml branch November 25, 2025 13:39
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.

2 participants