Accessing public properties is the last option used by PropertyAccessor.
It tries to access the value using the below methods first before using
the property directly. For example, if you have a public property that
has a getter method, it will use the getter.

The getValue() method also supports reading using getters. The method will
be created using common naming conventions for getters. It camelizes the
property name (first_name becomes FirstName) and prefixes it with
get. So the actual method becomes getFirstName():

And it doesn't even stop there. If there is no getter found, the accessor will
look for an isser or hasser. This method is created using the same way as
getters, this means that you can do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// ...classPerson{private$author=true;private$children=array();publicfunctionisAuthor(){return$this->author;}publicfunctionhasChildren(){return0!==count($this->children);}}$person=newPerson();if($accessor->getValue($person,'author')){var_dump('He is an author');}if($accessor->getValue($person,'children')){var_dump('He has children');}

The PropertyAccess component checks for methods called add<SingularOfThePropertyName>()
and remove<SingularOfThePropertyName>(). Both methods must be defined.
For instance, in the previous example, the component looks for the addChild()
and removeChild() methods to access to the children property.
The Inflector component is used to find the singular of a property name.

If available, adder and remover methods have priority over a setter method.

// ...$accessorBuilder=PropertyAccess::createPropertyAccessorBuilder();// enables magic __call$accessorBuilder->enableMagicCall();// disables magic __call$accessorBuilder->disableMagicCall();// checks if magic __call handling is enabled$accessorBuilder->isMagicCallEnabled();// true or false// At the end get the configured property accessor$accessor=$accessorBuilder->getPropertyAccessor();// Or all in one$accessor=PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor();

Or you can pass parameters directly to the constructor (not the recommended way):