Back to Phpstan

property.notFound

website/errors/property.notFound.md

2.2.11.4 KB
Original Source

Code example

php
<?php declare(strict_types = 1);

class Foo
{
	public string $name = 'hello';
}

$foo = new Foo();
echo $foo->surname; // ERROR: Access to an undefined property Foo::$surname.

Why is it reported?

The code accesses a property that does not exist on the object. This typically indicates a typo in the property name, a missing property declaration, or accessing a property on a wrong type. At runtime this would trigger a deprecation notice (or an error in strict scenarios) and return null.

How to fix it

There are many ways to solve this error. Read the comprehensive article Solving PHPStan error "Access to an undefined property" for all of them, including: