Skip to content
Permalink
Browse files

Fix #2423 - pass by ref variable status after byref assignment

  • Loading branch information
muglug committed Dec 5, 2019
1 parent 8ff33ee commit 19838fc7f557f87ae5009c1064e86c244f2e8bc4
@@ -277,6 +277,10 @@ public static function analyze(
}

if ($array_var_id && isset($context->vars_in_scope[$array_var_id])) {
if ($context->vars_in_scope[$array_var_id]->by_ref) {
$assign_value_type->by_ref = true;
}

// removes dependennt vars from $context
$context->removeDescendents(
$array_var_id,
@@ -419,7 +423,7 @@ public static function analyze(
);
}

if (isset($context->byref_constraints[$var_id])) {
if (isset($context->byref_constraints[$var_id]) || $assign_value_type->by_ref) {
$statements_analyzer->registerVariableUses([$location->getHash() => $location]);
}
} elseif ($assign_var instanceof PhpParser\Node\Expr\List_
@@ -1025,6 +1029,8 @@ public static function analyzeAssignmentRef(
return false;
}

$assignment_type->by_ref = true;

$lhs_var_id = ExpressionAnalyzer::getVarId(
$stmt->var,
$statements_analyzer->getFQCLN(),
@@ -1317,6 +1317,16 @@ function keys(): array {
echo gettype($k);
}'
],
'byRefVariableAfterAssignment' => [
'<?php
class A {
public string $value = "";
public function writeByRef(string $value): void {
$update =& $this->value;
$update = $value;
}
}'
],
];
}

0 comments on commit 19838fc

Please sign in to comment.
You can’t perform that action at this time.