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

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

sagittariusx/beluga.dynamic-properties
======================================

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

0.1.0(9y ago)1954LGPLv3PHPPHP &gt;=7.0

Since Aug 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/SagittariusX/Beluga.DynamicProperties)[ Packagist](https://packagist.org/packages/sagittariusx/beluga.dynamic-properties)[ RSS](/packages/sagittariusx-belugadynamic-properties/feed)WikiDiscussions master Synced today

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

Beluga.DynamicProperties
========================

[](#belugadynamicproperties)

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 `\Beluga\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.

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

[](#installation)

Install it via

```
composer require sagittariusx/beluga.dynamic-properties

```

or inside the `composer.json`:

```
   "require": {
      "php": ">=7.0",
      "sagittariusx/beluga.dynamic-properties": "^0.1.0"
   },
```

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 `\Beluga\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 Beluga\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 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 `Beluga\DynamicProperties\ExplicitGetter`with the `Beluga\DynamicProperties\ExplicitGetterSetter` class and implement the required set???() methods

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

use Beluga\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.

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

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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

3615d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ccdb1997342e9edfb20d481ebea751f251b7ef837c7a8622e6b464f56243a0f4?d=identicon)[SagittariusX](/maintainers/SagittariusX)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sagittariusx-belugadynamic-properties/health.svg)

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

###  Alternatives

[christophrumpel/artisan-benchmark

Benchmark Artisan Commands

18380.9k](/packages/christophrumpel-artisan-benchmark)[pugx/formable

The PUGX Symfony Form Generator

112.7k](/packages/pugx-formable)

PHPackages © 2026

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