Download the PHP package phpgt/propfunc without Composer
On this page you can find all versions of the php package phpgt/propfunc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpgt/propfunc
More information about phpgt/propfunc
Files in phpgt/propfunc
Package propfunc
Short Description Property accessor and mutator functions.
License MIT
Informations about the package propfunc
Property accessor and mutator functions.
Property accessors and mutators are commonly referred to as "getter" and "setter" functions. This library uses PHP's Magic Methods to easily hook up getter and setter functions that are exposed externally as normal properties, via the MagicProp
trait.
Why? This kind of functionality can certainly be seen as a hack, but sometimes hacks are necessary. Specifically PHP.Gt is implementing the DOM standard in PHP which requires certain properties to have "live" or "readonly" functionality, which is only possible using magic get and set functions. This library simply holds the reusable behaviour for other repositories that require it.
Example usage: Read-only properties that are calculated upon access
See the class Day
below, which represents a day in time:
See the code below which uses the Day
class. It can access the properties, but not mutate them.
Usages
- Read only properties - as with the above example, properties can be made read-only. This feature is coming to the PHP language, but without the ability to define the accessor logic.
- Live properties - if a property's value is required to update depending on certain conditions, a getter function is required.
- Property validation - if a property's value can't simply be validated by its type alone, the setter function can be used to ensure the value meets validation criteria.