Cannot access %s property %s::$%s
Description
Properties have visibility, which restrict access to the defining class (private), or the class and its children (protected).
This applies to static and normal properties.
Example
<?php
class X {
private string $property = 'abc';
}
echo (new X)->property;
?>
Literal Examples
- Cannot access private property X::$property
- Cannot access protected property X::$property
Alternatives
- Relax the visibility constraint to
protectedorpublicto make the property available to the calling context. - Create a method to access the value of the property.
- Extends the class and change the visibility level of the property from
protectedtopublic. This has no effect forprivate.