PHPackages                             niirrty/niirrty.dynprop - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. niirrty/niirrty.dynprop

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

niirrty/niirrty.dynprop
=======================

A dynamic PHP class properties library.

0.6.2(2y ago)0302MITPHPPHP &gt;=8.1CI failing

Since Oct 30Pushed 2y agoCompare

[ Source](https://github.com/Niirrty/Niirrty.DynProp)[ Packagist](https://packagist.org/packages/niirrty/niirrty.dynprop)[ RSS](/packages/niirrty-niirrtydynprop/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (2)

Niirrty.DynProp
===============

[](#niirrtydynprop)

This is an PHP8 implementation to easy generate a little bit of "magic" extra functionality to you're PHP classes.

Installation
------------

[](#installation)

inside the `composer.json`:

```
{
   "require": {
      "php": ">=8.1",
      "niirrty/niirrty.dynprop": "~0.6"
   }
}
```

Usage
-----

[](#usage)

The usage is really simple.

### Why should I use dynamic properties?

[](#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](https://www.jetbrains.com/phpstorm/) or [Netbeans](https://netbeans.org/features/php/)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`

```
/**
 * …
 *
 * @property-read string $foo Description of the property…
 */
```

For read + write access you only have to replace `@property-read` with `@property`.

### Dynamic property read access

[](#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.

```
# include \dirname( __DIR__ ) . '/vendor/autoload.php';

use Niirrty\DynProp\ExplicitGetter;

/**
 * @property-read string $foo …
 * @property-read bool   $bar …
 */
class MyClass extends ExplicitGetter
{

   private $properties = [
      'foo'      => 'foo',
      'bar'      => true
   ];

   public function getFoo() : string
   {
      return $this->properties[ 'foo' ];
   }
   public function getBar() : bool
   {
      return $this->properties[ 'bar' ];
   }

}
```

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

[](#dynamic-property-readwrite-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

```
#include \dirname( __DIR__ ) . '/vendor/autoload.php';

use Niirrty\DynProp\ExplicitGetterSetter;

/**
 * @property      string $foo …
 * @property-read bool   $bar …
 */
class MyClass extends ExplicitGetterSetter
{

   private $properties = [
      'foo'      => 'foo',
      'bar'      => true
   ];

   public function getFoo() : string
   {
      return $this->properties[ 'foo' ];
   }

   public function getBar() : bool
   {
      return $this->properties[ 'bar' ];
   }

   public function setFoo( string $value ) : MyClass
   {
      if ( \strlen( $value ) < 1 )
      {
         throw new \LogicException( 'Foo can not use an empty string' );
      }
      $this->properties[ 'foo' ] = $value;
      return $this;
   }

}
```

### Special cases: Ignore Getters and/or Setters

[](#special-cases-ignore-getters-andor-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:

```
   public function __construct()
   {

      // ignore the getBar() method
      $this->ignoreGetProperties = [ 'bar' ];

      // If the class extends from ExplicitGetterSetter you can also
      // Define the setters that should be ignored. e.g.: ignore setFoo()
      $this->ignoreSetProperties = [ 'foo' ];

   }
```

###  Health Score

28

—

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~580 days

Total

5

Last Release

886d ago

PHP version history (3 changes)0.1.0PHP &gt;=7.1

0.4.0PHP &gt;=8.0

0.6.2PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/56201fee0dd151f8d0ce7dfe228cc74aa1bae7949664bc8644cdb5620e329b88?d=identicon)[Niirrty](/maintainers/Niirrty)

---

Top Contributors

[![Niirrty](https://avatars.githubusercontent.com/u/33220884?v=4)](https://github.com/Niirrty "Niirrty (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/niirrty-niirrtydynprop/health.svg)

```
[![Health](https://phpackages.com/badges/niirrty-niirrtydynprop/health.svg)](https://phpackages.com/packages/niirrty-niirrtydynprop)
```

###  Alternatives

[canducci/zipcode

ZipCode From Brazil

4556.0k](/packages/canducci-zipcode)[relaticle/activity-log

Reusable Filament plugin that renders a unified activity-log timeline for any Eloquent model

1314.6k4](/packages/relaticle-activity-log)[leek/filament-subtenant-scope

Second-level tenancy scope (e.g. service area, region, location) for Filament panels — topnav dropdown filter that scopes Eloquent queries globally.

281.0k](/packages/leek-filament-subtenant-scope)[buchin/google-suggest

Google keyword suggestion scraper

124.4k](/packages/buchin-google-suggest)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
