Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test cases for array<mixed> parameter to show superglobal-specifi…
…c behavior

The bug only affects superglobals because they are not tracked in
expressionTypes by default (they use lazy default types via
getVariableType()). This means during scope merging in
createConditionalExpressions(), the parameter $a exists in both
branches' expressionTypes and gets correctly filtered out, while
$_SESSION only exists in the isset-true branch, causing it to become
a spurious type guard.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
  • Loading branch information
2 people authored and staabm committed May 14, 2026
commit 99c79c20d86085236054ab7fd6ae11bd05a6be62
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14610.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ function test(): void
assertType('array<mixed>', $_SESSION);
}
}

/** @param array<mixed> $a */
function testWithParam($a): void
{
$value = 0;

if (isset($a['test'])) {
$value = rand(0,3);
if ($value == 1) {
}
}

assertType('int<0, 3>', $value);

if ($value == 0) {
assertType('array<mixed>', $a);
}
}
16 changes: 16 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-14610.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,19 @@ function testWithDifferentKey(): void
$result = isset($_SESSION['other']);
}
}

/** @param array<mixed> $a */
function testWithParam($a): void
{
$value = 0;

if (isset($a['test'])) {
$value = rand(0,3);
if ($value == 1) {
}
}

if ($value == 0) {
$result = isset($a['test']);
}
}