Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Php/PhpVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ public function supportsTrueAndFalseStandaloneType(): TrinaryLogic
return IntegerRangeType::fromInterval(80200, null)->isSuperTypeOf($this->phpVersions)->result;
}

public function supportsMaxMemoryLimit(): TrinaryLogic
{
return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result;
}

}
4 changes: 4 additions & 0 deletions src/Type/Php/IniGetReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function getTypeFromFunctionCall(
'precision' => $numericString,
];

if ($scope->getPhpVersion()->supportsMaxMemoryLimit()->yes()) {
$types['max_memory_limit'] = new StringType();
}

$argType = $scope->getType($args[0]->value);
$results = [];
foreach ($argType->getConstantStrings() as $constantString) {
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Analyser/nsrt/ini-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ function doFoo() {
}
assertType('string|false', ini_get($key));
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 ;)

} else {
assertType('string|false', ini_get("max_memory_limit"));
}
assertType('string|false', ini_get("max_memory_limit"));
}
Loading