diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php index db382c4f914..a5304b21688 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php @@ -164,13 +164,22 @@ public static function getGlobalConstType( case 'PHP_MAJOR_VERSION': case 'PHP_MINOR_VERSION': case 'PHP_RELEASE_VERSION': - case 'PHP_DEBUG': case 'PHP_FLOAT_DIG': + return Type::getInt(); + case 'PHP_INT_MIN': + return Type::getInt(false, -9223372036854775808); + + case 'PHP_DEBUG': case 'PHP_ZTS': - return Type::getInt(); + if ($codebase->analysis_php_version_id >= 8_04_00) { + return Type::getBool(); + } + return Type::getIntRange(0, 1); case 'PHP_INT_MAX': + return Type::getInt(false, 9223372036854775807); + case 'PHP_INT_SIZE': case 'PHP_MAXPATHLEN': case 'PHP_VERSION_ID': diff --git a/tests/ConstantTest.php b/tests/ConstantTest.php index 68b10f2b641..e415b25a40c 100644 --- a/tests/ConstantTest.php +++ b/tests/ConstantTest.php @@ -2157,6 +2157,31 @@ interface BarInterface extends MainInterface {} class FooBar implements FooInterface, BarInterface {} PHP, ], + 'phpIntMaxValueValid' => [ + 'code' => ' 100) {} + ', + ], + 'phpIntMinValueValid' => [ + 'code' => ' [ + 'code' => ' [ + 'code' => ' [], + 'ignored_issues' => [], + 'php_version' => '8.4', + ], ]; } @@ -2724,6 +2749,34 @@ class C { 'error_levels' => [], 'php_version' => '8.2', ], + 'phpIntMaxValue' => [ + 'code' => ' 'TypeDoesNotContainType', + ], + 'phpIntMinValue' => [ + 'code' => ' -100) {} + ', + 'error_message' => 'TypeDoesNotContainType', + ], + 'phpDebug' => [ + 'code' => ' 'TypeDoesNotContainType', + ], + 'phpDebug84' => [ + 'code' => ' 'TypeDoesNotContainType', + 'error_levels' => [], + 'php_version' => '8.4', + ], ]; } }