Skip to content

Commit fa53050

Browse files
committed
fix $_FILES
1 parent b5f6da7 commit fa53050

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Psalm\Internal\Codebase\TaintFlowGraph;
1414
use Psalm\Internal\DataFlow\DataFlowNode;
1515
use Psalm\Internal\DataFlow\TaintSource;
16+
use Psalm\Internal\Type\TypeCombiner;
1617
use Psalm\Issue\ImpureVariable;
1718
use Psalm\Issue\InvalidScope;
1819
use Psalm\Issue\PossiblyUndefinedGlobalVariable;
@@ -767,7 +768,14 @@ public static function getGlobalType(string $var_id, int $codebase_analysis_php_
767768

768769
$type = new TKeyedArray($values);
769770

770-
return new Union([$type]);
771+
// $_FILES['userfile']['...'] case
772+
$named_type = new TArray([Type::getNonEmptyString(), new Union([$type])]);
773+
774+
// by default $_FILES is an empty array
775+
$default_type = new TArray([Type::getNever(), Type::getNever()]);
776+
777+
// ideally we would have 3 separate arrays with distinct types, but that isn't possible with psalm atm
778+
return TypeCombiner::combine([$default_type, $type, $named_type]);
771779
}
772780

773781
if ($var_id === '$_SESSION') {

0 commit comments

Comments
 (0)