PHPackages                             angrybytes/domainobject - 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. angrybytes/domainobject

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

angrybytes/domainobject
=======================

A simple DomainObject implementation that provides simulated properties

4.0.1(5mo ago)441.4k↓13.9%2MITPHPPHP 8.2 - 8.5CI passing

Since May 5Pushed 2mo ago6 watchersCompare

[ Source](https://github.com/AngryBytes/domainobject)[ Packagist](https://packagist.org/packages/angrybytes/domainobject)[ RSS](/packages/angrybytes-domainobject/feed)WikiDiscussions 4.0 Synced 1mo ago

READMEChangelog (6)Dependencies (4)Versions (15)Used By (0)

DomainObject
============

[](#domainobject)

This is a simple class that signifies classes that extend it are a [DomainObject](http://c2.com/cgi/wiki?DomainObject). In a more practical sense it offers a [properties](http://en.wikipedia.org/wiki/Property_(programming))implementation, that is lacking from PHP.

Why
---

[](#why)

We believe in a plain old php objects (POPO) for modelling your domain. These objects should hold no logic other than their core values. A DomainObject should have a direct link to an entity in your Universe of Discourse.

This class helps you do that in a generic way. It has some niceties such as support for accessing your properties through both functions and object property notation. But mostly, it is a strong signal that the class that's extending it is, in fact, a DomainObject.

### Why not simply rely on public variables?

[](#why-not-simply-rely-on-public-variables)

Using simple variables like:

```
class Person
{
    public $name;
}
```

Works pretty well for most simple properties.

Imagine the following though:

```
class Person
{
    public $firstName;

    public $lastName;

    public function getFullName()
    {
        return $this->firstName . ' ' . $this->lastName;
    }
}
```

In order to get the full name for a person (first + last), you need to write a method. Now you have to mix both properties and methods in your API. This is not very consistent and rather inflexible.

Example
-------

[](#example)

```
