Menu

← Back to assign.*

Error Identifier: assign.invalidExpr

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

class Foo
{
	public function doFoo(\stdClass $s): void
	{
		$s->foo() = 'test';
	}
}

Why is it reported? #

The expression on the left side of the assignment is not something that can be assigned to. In PHP, only variables, properties, array offsets, and static properties can appear on the left side of an assignment. Expressions like method calls, function calls, or other non-lvalue expressions cannot be assigned to and will cause a compile-time error.

In the example above, $s->foo() is a method call, not a property access or variable, so it cannot be used as the target of an assignment.

How to fix it #

Assign to a valid target such as a variable or a property:

 <?php declare(strict_types = 1);
 
 class Foo
 {
 	public function doFoo(\stdClass $s): void
 	{
-		$s->foo() = 'test';
+		$s->foo = 'test';
 	}
 }

Non-ignorable error #

This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.

Rules that report this error #

  • PHPStan\Rules\Operators\InvalidAssignVarRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.