diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php index 9590811e9..e55f6e49a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php @@ -86,7 +86,7 @@ class ElseAnalyzer foreach ($changed_var_ids as $changed_var_id => $_) { foreach ($else_context->vars_in_scope as $var_id => $_) { - if (preg_match('/' . preg_quote($changed_var_id, '/') . '[\]\[\-]/', $var_id) + if (\preg_match('/' . \preg_quote($changed_var_id, '/') . '[\]\[\-]/', $var_id) && !\array_key_exists($var_id, $changed_var_ids) ) { unset($else_context->vars_in_scope[$var_id]);