From ff83f93994db15587ee0a6d1978ff12272d62b96 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 25 Nov 2025 09:32:50 +0100 Subject: [PATCH 1/2] [PHP 8.5] ini_get("max_memory_limit") is a string --- src/Php/PhpVersions.php | 5 +++++ src/Type/Php/IniGetReturnTypeExtension.php | 4 ++++ tests/PHPStan/Analyser/nsrt/ini-get.php | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/src/Php/PhpVersions.php b/src/Php/PhpVersions.php index cc2ea94c98..993ee23acf 100644 --- a/src/Php/PhpVersions.php +++ b/src/Php/PhpVersions.php @@ -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; + } + } diff --git a/src/Type/Php/IniGetReturnTypeExtension.php b/src/Type/Php/IniGetReturnTypeExtension.php index 21aab0b82f..60795cd7af 100644 --- a/src/Type/Php/IniGetReturnTypeExtension.php +++ b/src/Type/Php/IniGetReturnTypeExtension.php @@ -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) { diff --git a/tests/PHPStan/Analyser/nsrt/ini-get.php b/tests/PHPStan/Analyser/nsrt/ini-get.php index 6751b3cc16..fbcd29c082 100644 --- a/tests/PHPStan/Analyser/nsrt/ini-get.php +++ b/tests/PHPStan/Analyser/nsrt/ini-get.php @@ -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")); + } else { + assertType('string|false', ini_get("max_memory_limit")); + } + assertType('string|false', ini_get("max_memory_limit")); } From 9624524ff7149f12035836c4c230da6e59859627 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 25 Nov 2025 10:35:16 +0100 Subject: [PATCH 2/2] more tests --- tests/PHPStan/Analyser/nsrt/ini-get.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/PHPStan/Analyser/nsrt/ini-get.php b/tests/PHPStan/Analyser/nsrt/ini-get.php index fbcd29c082..c11655be35 100644 --- a/tests/PHPStan/Analyser/nsrt/ini-get.php +++ b/tests/PHPStan/Analyser/nsrt/ini-get.php @@ -32,5 +32,10 @@ function doFoo() { } else { assertType('string|false', ini_get("max_memory_limit")); } - assertType('string|false', ini_get("max_memory_limit")); + if (PHP_VERSION_ID >= 80300) { + assertType('string|false', ini_get("max_memory_limit")); + } + if (PHP_VERSION_ID < 80300) { + assertType('string|false', ini_get("max_memory_limit")); + } }