Skip to content

Live properties

Greg Bowler edited this page May 16, 2016 · 7 revisions

One of the underlying principals of the DOM is that properties of Nodes can be "live", meaning that their values change as the DOM changes. In PHP, this can only be implemented by using getters - otherwise known as Magic Methods.

Any class within this project that implements a getter or setter should use the LiveProperty trait. This is due to the fact that things become unpredictable or confusing if an object uses a trait or extends a class that already has a __get method.

prop_get_* and prop_set_*

As an example of how live properties are used, let's look at the ParentNode trait. On line 25, we can see the getter for the children property, called prop_get_children. To show this live property in action, look at the next method in the trait, firstElementChild. The firstElementChild method calls the trait's own live property directly as $this->children.