Follow-up from https://gerrit.wikimedia.org/r/c/mediawiki/libs/less.php/+/879851/2/lib/Less/Tree.php.
In the wikimedia/less.php library, we internally have a Less_Tree class that presents invidual symbols of the Less input as parsed by Less_Parser. The tree nodes are often checked during compilation to distinguish tree nodes that are considered "value-holding". This is a trait common to most Less_Tree subclasses, but the value property is not declared as part of this class.
Instead, individual callers use property_exists(, 'value') to determine whether the subclass implements the property, before accessing it.
Problem:
- It is an anti-pattern to use reflection in this way and makes code more difficult to understand, debug, as more difficult to write correctly for contributors. This is in part also why Phan static analysis is giving the code false-positive warnings about unsafe property access, which we currently suppress.
- It is easy to forget this check, leading to runtime errors like the one I fixed in https://gerrit.wikimedia.org/r/c/mediawiki/libs/less.php/+/879851.
- Moving the public $value; declaration to the parent class is insufficient, because we require a distinction between nodes that can't carry a value, and nodes that hold an actual empty/null value.
- It might improve runtime latency if we remove the check (unconfirmed).
Options:
- Base class property with special reserved value?
- Boolean method in base class that subclasses override to return true?
- Intermediary subclass?