PHPackages                             dbx12/base-object - 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. dbx12/base-object

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

dbx12/base-object
=================

Configurable objects, inspired by the Yii2 framework.

v1.0.1(4y ago)05MITPHP

Since Jul 29Pushed 4y ago1 watchersCompare

[ Source](https://github.com/DBX12/base-object)[ Packagist](https://packagist.org/packages/dbx12/base-object)[ RSS](/packages/dbx12-base-object/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Base object
===========

[](#base-object)

[![Build](https://github.com/DBX12/base-object/actions/workflows/php.yml/badge.svg)](https://github.com/DBX12/base-object/actions/workflows/php.yml)

This library is heavily inspired by the configurable objects of the [Yii2 framework](https://www.yiiframework.com/)

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

[](#installation)

As with any composer library:

`composer require dbx12/base-object`

Concept
-------

[](#concept)

The base object allows you to set the properties of a class with a configuration array. By default, only **public and protected** properties can be set this way. If you want to set a private property, define a setter for it. The pattern for setter is `set` + property name, e.g. for the property `$name` -&gt; `function setName($value)`. The getter names are created similar (for the same example: `function getName()`).

If you expose your private or protected properties with public setters and getters, you can help your IDE by annotating your class with `@property-read` and `@property-write` annotations. If you have a getter and a setter, you can combine them into `@property`. For above example (without the setter), you would write `@property-write string $name`.

Usage
-----

[](#usage)

**Default (Without setter)**

```
class MyObject extends \dbx12\baseObject\BaseObject {
    public $publicVariable;
    protected $protectedVariable;
    private $privateVariable;
}

// this will fail with an UnknownPropertyException because setting $privateVariable is not allowed
$instance = new MyObject([
    'publicVariable' => 'publicValue',
    'protectedVariable' => 'protectedValue',
    'privateVariable' => 'privateValue',
]);
```

**With protected setter**

```
class MyObject extends \dbx12\baseObject\BaseObject {
    public $publicVariable;
    protected $protectedVariable;
    private $privateVariable;

    protected function setPrivateVariable($value): void
    {
        $this->privateVariable = $value;
    }
}

// this will succeed
$instance = new MyObject([
    'publicVariable' => 'publicValue',
    'protectedVariable' => 'protectedValue',
    'privateVariable' => 'privateValue',
]);

// and this will produce an error as the setter is not visible from the global scope
$myObject->setPrivateVariable('bar');
```

**Without a public getter**

```
class MyObject extends \dbx12\baseObject\BaseObject {
    public $publicVariable;
    protected $protectedVariable;
    private $privateVariable;

    protected function setPrivateVariable($value): void
    {
        $this->privateVariable = $value;
    }
}

$myObject = new MyObject([
    'publicVariable' => 'publicValue',
    'protectedVariable' => 'protectedValue',
    'privateVariable' => 'privateValue',
]);

// this will throw an UnknownPropertyException
echo $myObject->protectedVariable;
```

**With a public getter**

```
/**
 * @property-read $protectedVariable
 */
class MyObject extends \dbx12\baseObject\BaseObject {
    public $publicVariable;
    protected $protectedVariable;
    private $privateVariable;

    protected function setPrivateVariable($value): void
    {
        $this->privateVariable = $value;
    }

    public function getProtectedVariable()
    {
        return $this->protectedVariable;
    }
}

$myObject = new MyObject([
    'publicVariable' => 'publicValue',
    'protectedVariable' => 'protectedValue',
    'privateVariable' => 'privateValue',
]);

// this will succeed
echo $myObject->getProtectedVariable();

// this will succeed and your IDE will show you a hint for it thanks to the @property-read annotation
echo $myObject->protectedVariable;
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Every ~115 days

Total

2

Last Release

1637d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7dd9e7c6d0c101b23d35ddde728a50a7263b43f2103416c3022cb5f6ca0fa7ab?d=identicon)[DBX12](/maintainers/DBX12)

---

Top Contributors

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

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/dbx12-base-object/health.svg)

```
[![Health](https://phpackages.com/badges/dbx12-base-object/health.svg)](https://phpackages.com/packages/dbx12-base-object)
```

###  Alternatives

[nuhel/filament-croppie

182.2k](/packages/nuhel-filament-croppie)[qinchen/web-utils

A web application common utils

111.4k](/packages/qinchen-web-utils)

PHPackages © 2026

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