diff --git a/src/Psalm/Checker/StatementsChecker.php b/src/Psalm/Checker/StatementsChecker.php index 799ad5a5e..e4307cdd5 100644 --- a/src/Psalm/Checker/StatementsChecker.php +++ b/src/Psalm/Checker/StatementsChecker.php @@ -40,6 +40,11 @@ class StatementsChecker extends SourceChecker implements StatementsSource */ public static $user_constants = []; + /** + * @var array + */ + public static $stub_constants = []; + /** * @param StatementsSource $source */ @@ -770,6 +775,10 @@ class StatementsChecker extends SourceChecker implements StatementsSource return ClassLikeChecker::getTypeFromValue($predefined_constants[$fq_const_name ?: $const_name]); } + if (isset(self::$stub_constants[$fq_const_name ?: $const_name])) { + return self::$stub_constants[$fq_const_name ?: $const_name]; + } + return null; } @@ -1054,6 +1063,7 @@ class StatementsChecker extends SourceChecker implements StatementsSource public static function clearCache() { self::$user_constants = []; + self::$stub_constants = []; ExpressionChecker::clearCache(); } diff --git a/src/Psalm/Visitor/DependencyFinderVisitor.php b/src/Psalm/Visitor/DependencyFinderVisitor.php index 2e17543d7..b32d2719d 100644 --- a/src/Psalm/Visitor/DependencyFinderVisitor.php +++ b/src/Psalm/Visitor/DependencyFinderVisitor.php @@ -355,6 +355,13 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P $var_type->queueClassLikesForScanning($this->project_checker); } } + } elseif ($node instanceof PhpParser\Node\Stmt\Const_) { + if ($this->project_checker->register_global_functions) { + foreach ($node->consts as $const) { + StatementsChecker::$stub_constants[$const->name] = + StatementsChecker::getSimpleType($const->value) ?: Type::getMixed(); + } + } } }