website/errors/property.notFound.md
<?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.
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.
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:
#[AllowDynamicProperties] attribute (PHP 8.2+)universalObjectCratesClasses for classes without predefined structure@property PHPDoc tags for magic properties@mixin PHPDoc tag for delegated property access