PHPackages                             uk/dynamic-properties - 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. uk/dynamic-properties

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

uk/dynamic-properties
=====================

Helping classes to use dynamic properties declared by get\*() and set\*() methods

0.2.0(9y ago)1281LGPLv3PHPPHP &gt;=7.0

Since Jun 26Pushed 9y ago2 watchersCompare

[ Source](https://github.com/UniKado/UK.DynamicProperties)[ Packagist](https://packagist.org/packages/uk/dynamic-properties)[ RSS](/packages/uk-dynamic-properties/feed)WikiDiscussions master Synced 2mo ago

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

UK.DynamicProperties
====================

[](#ukdynamicproperties)

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

If you extend you're class from one of the classes of `\UK\DynamicProperties` so it adds dynamic class instance properties with read or read+write access. It requires only the presence of some get\*() and/or set\*() methods.

Status
------

[](#status)

[![Build Status](https://camo.githubusercontent.com/88509b9494baac94bf42920776029e41fe54e716f8d12ff5648b7a781fb6ec13/68747470733a2f2f7472617669732d63692e6f72672f556e694b61646f2f554b2e44796e616d696350726f706572746965732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/UniKado/UK.DynamicProperties) [![Code Coverage](https://camo.githubusercontent.com/67f08efb3c424f585e0366eac803dd30c7cf0aaf350a73deefe485fea8822550/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f556e694b61646f2f554b2e44796e616d696350726f706572746965732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/UniKado/UK.DynamicProperties/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/7ad703fe28005fb228e1059257a8f40534164319a35a0717a5597b38a2c8867b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f556e694b61646f2f554b2e44796e616d696350726f706572746965732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/UniKado/UK.DynamicProperties/?branch=master)

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

[](#installation)

```
composer require uk/dynamic-properties

```

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\DynamicProperties\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 UK\DynamicProperties\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 docblock below.

### Dynamic property read+write access

[](#dynamic-property-readwrite-access)

If you also need write access to the properties you must replace the `UK\DynamicProperties\ExplicitGetter`with the `UK\DynamicProperties\ExplicitGetterSetter` class an implement the required set???() methods

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

use UK\DynamicProperties\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.

Fo 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 getter that should be ignored. e.g.: ignore setFoo()
      $this->ignoreSetProperties = [ 'foo' ];

   }
```

End of document :-)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3610d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/89b9d7c9dcc70d30f432d252244a7727383b73059ddc2cc13210b4cd0cfa2800?d=identicon)[UK](/maintainers/UK)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/uk-dynamic-properties/health.svg)

```
[![Health](https://phpackages.com/badges/uk-dynamic-properties/health.svg)](https://phpackages.com/packages/uk-dynamic-properties)
```

PHPackages © 2026

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