Error Identifier: property.notFound
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 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:
- Fixing the property name if it’s a typo
- Narrowing the type the property is accessed on
- Declaring the missing property on the class
- Adding
#[AllowDynamicProperties]attribute (PHP 8.2+) - Configuring
universalObjectCratesClassesfor classes without predefined structure - Adding
@propertyPHPDoc tags for magic properties - Using
@mixinPHPDoc tag for delegated property access - Using framework-specific extensions
- Writing a custom class reflection extension
How to ignore this error #
You can use the identifier property.notFound to ignore this error using a comment:
// @phpstan-ignore property.notFound
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: property.notFound