Skip to content

Commit

Permalink
Fix wrong PHP_INT_MAX/MIN and PHP_DEBUG PHP 8.4 type
Browse files Browse the repository at this point in the history
* Fix #11189
* Fix PHP_DEBUG constant for PHP 8.4 part of #11107
  • Loading branch information
kkmuffme committed Dec 23, 2024
1 parent 5abbdf3 commit 56d96ec
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
use function implode;
use function strtolower;

use const PHP_INT_MAX;
use const PHP_INT_MIN;

/**
* @internal
*/
Expand Down Expand Up @@ -164,13 +167,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, PHP_INT_MIN);

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, PHP_INT_MAX);

case 'PHP_INT_SIZE':
case 'PHP_MAXPATHLEN':
case 'PHP_VERSION_ID':
Expand Down
55 changes: 55 additions & 0 deletions tests/ConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,19 @@ interface BarInterface extends MainInterface {}
class FooBar implements FooInterface, BarInterface {}
PHP,
],
'phpDebugValid' => [
'code' => '<?php
if (PHP_DEBUG === 0) {}
',
],
/*'phpDebugValid84' => [
'code' => '<?php
if (PHP_DEBUG === false) {}
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.4',
],*/
];
}

Expand Down Expand Up @@ -2724,6 +2737,48 @@ class C {
'error_levels' => [],
'php_version' => '8.2',
],
'phpIntMaxValue' => [
'code' => '<?php
$max = PHP_INT_MAX;
if ($max < 100) {}
',
'error_message' => 'TypeDoesNotContainType',
],
'phpIntMinValue' => [
'code' => '<?php
$min = PHP_INT_MIN;
if ($min > -100) {}
',
'error_message' => 'TypeDoesNotContainType',
],
'phpIntMaxValueRedundant' => [
'code' => '<?php
$max = PHP_INT_MAX;
if ($max > 100) {}
',
'error_message' => 'RedundantCondition',
],
'phpIntMinValueRedundant' => [
'code' => '<?php
$min = PHP_INT_MIN;
if ($min < -100) {}
',
'error_message' => 'RedundantCondition',
],
'phpDebug' => [
'code' => '<?php
if (PHP_DEBUG === false) {}
',
'error_message' => 'TypeDoesNotContainType',
],
/*'phpDebug84' => [
'code' => '<?php
if (PHP_DEBUG === 0) {}
',
'error_message' => 'TypeDoesNotContainType',
'error_levels' => [],
'php_version' => '8.4',
],*/
];
}
}

0 comments on commit 56d96ec

Please sign in to comment.