Skip to content

Fix nested array access evaluation for null coalescing - #1175

Open
ydah wants to merge 1 commit into
nikic:masterfrom
ydah:fix-nested-coalesce-fetch
Open

ydah wants to merge 1 commit into
nikic:masterfrom
ydah:fix-nested-coalesce-fetch

Conversation

@ydah

@ydah ydah commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

ConstExprEvaluator applies isset-style fetching only to the outermost array offset on the left of ??. Inner offsets can therefore cause evaluateSilently() to throw instead of returning the fallback:

$expr = $parser->parse('<?php ["a" => 1]["b"]["c"] ?? 2;')[0]->expr;
$evaluator->evaluateSilently($expr);
// Before: exception for undefined key "b"
// After:  2

$expr = $parser->parse('<?php null["a"]["b"] ?? 3;')[0]->expr;
$evaluator->evaluateSilently($expr);
// Before: exception for accessing an offset on null
// After:  3

Propagate isset context through nested array offsets, while evaluating offset expressions normally and preserving right-hand-side short-circuiting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant