1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Prevent access to possibly unset var

This commit is contained in:
Brown 2020-08-17 15:25:13 -04:00
parent f48a362fcd
commit 12798d1cab

View File

@ -364,13 +364,18 @@ class LoopAnalyzer
}
foreach ($asserted_var_ids as $var_id) {
if (!isset($inner_context->vars_in_scope[$var_id])
|| $inner_context->vars_in_scope[$var_id]->getId()
!== $pre_loop_context->vars_in_scope[$var_id]->getId()
|| $inner_context->vars_in_scope[$var_id]->from_docblock
!== $pre_loop_context->vars_in_scope[$var_id]->from_docblock
if ((!isset($inner_context->vars_in_scope[$var_id])
|| $inner_context->vars_in_scope[$var_id]->getId()
!== $pre_loop_context->vars_in_scope[$var_id]->getId()
|| $inner_context->vars_in_scope[$var_id]->from_docblock
!== $pre_loop_context->vars_in_scope[$var_id]->from_docblock
)
) {
$inner_context->vars_in_scope[$var_id] = clone $pre_loop_context->vars_in_scope[$var_id];
if (isset($pre_loop_context->vars_in_scope[$var_id])) {
$inner_context->vars_in_scope[$var_id] = clone $pre_loop_context->vars_in_scope[$var_id];
} else {
unset($inner_context->vars_in_scope[$var_id]);
}
}
}