Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/Analyser/ExprHandler/MethodCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
}

} else {
$nodeScopeResolver->callNodeCallback($nodeCallback, new InvalidateExprNode($normalizedExpr->var), $scope, $storage);
$scope = $scope->invalidateExpression($normalizedExpr->var, true);
$throwPoints[] = InternalThrowPoint::createImplicit($scope, $expr);
}
$hasYield = $hasYield || $argsResult->hasYield();
Expand Down
92 changes: 92 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-3831.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php declare(strict_types = 1);

namespace Bug3831Nsrt;

use function PHPStan\Testing\assertType;

class DynamicMethodCall
{
public int $counter = 0;

/** @var array<string> */
public array $footer = [];

public function test(): void
{
$this->counter = 0;
assertType('0', $this->counter);

$this->{'increment'}();
assertType('int', $this->counter);
}

public function testDynamicVar(): void
{
$this->footer = [];
assertType('array{}', $this->footer);

$method = 'compileSection';
$this->{$method}();
assertType('array<string>', $this->footer);
}

private function increment(): int
{
$this->counter++;
return 0;
}

private function compileSection(): void
{
$this->footer[] = 'section-name';
}
}

class Template
{
/** @var array<string> */
public $footer = [];

public function render(): string
{
$content = '';
$this->footer = [];

$this->{'compileSection'}();

if (count($this->footer) > 0) {
$content = str_replace('some', 'thing', $content);
}
return $content;
}

private function compileSection(): void
{
$this->footer[] = 'section-name';
}
}

class TemplateDynamicVar
{
/** @var array<string> */
public $footer = [];

public function render(): string
{
$content = '';
$this->footer = [];

$method = 'compileSection';
$this->{$method}();

if (count($this->footer) > 0) {
$content = str_replace('some', 'thing', $content);
}
return $content;
}

private function compileSection(): void
{
$this->footer[] = 'section-name';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,9 @@ public function testBug11146(): void
$this->analyse([__DIR__ . '/data/bug-11146.php'], []);
}

public function testBug3831(): void
{
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-3831.php'], []);
}

}
Loading