Download the PHP package niirrty/niirrty.dynprop without Composer
On this page you can find all versions of the php package niirrty/niirrty.dynprop. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download niirrty/niirrty.dynprop
More information about niirrty/niirrty.dynprop
Files in niirrty/niirrty.dynprop
Package niirrty.dynprop
Short Description A dynamic PHP class properties library.
License MIT
Informations about the package niirrty.dynprop
Niirrty.DynProp
This is an PHP8 implementation to easy generate a little bit of "magic" extra functionality to you're PHP classes.
Installation
inside the composer.json
:
Usage
The usage is really simple.
Why should I use dynamic properties?
You should not use it but you can, if you see the advantages.
Most modern IDE's like PHPStorm or Netbeans supports the dynamic properties with the code completion feature if the Properties have the correct PHP-Doc tag notation.
It means for example, if you provide a dynamic readonly property with the name $foo
of type string
For read + write access you only have to replace @property-read
with @property
.
Dynamic property read access
If you have an class that define methods for getting some instance properties and they are with an name format
like getPropertyName1()
or getPropertyName2()
etc. pp. You only must extend the class from the
\UK\DynProp\ExplicitGetter
class and you can access the Properties directly like
$myClassInstance->propertyName1
or $myClassInstance->propertyName2
for read access.
The class will always work like before but with the extra properties.
Remember to do not forget to write the required class documentation for the dynamic available read only properties, like in the example doc-block below.
Dynamic property read+write access
If you also need write access to the properties you must replace the Niirrty\DynProp\ExplicitGetter
with the Niirrty\DynProp\ExplicitGetterSetter
class and implement the required set???() methods
Special cases: Ignore Getters and/or Setters
Often not all get and/or set methods should be usable as dynamic properties.
For this cases you can explicit declare the names of the properties that should not be accessible by the dynamic way.
For it you have to define this dynamic property names inside the constructor of the extending class: