PHPackages                             david-garcia/value-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. david-garcia/value-object

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

david-garcia/value-object
=========================

Just another library to handle Value Objects and prevent the bad habit of Primitive Obsession

0.2.0(5y ago)08MITPHPPHP &gt;= 7.4

Since Feb 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/DavidGarciaCat/php-value-object)[ Packagist](https://packagist.org/packages/david-garcia/value-object)[ RSS](/packages/david-garcia-value-object/feed)WikiDiscussions master Synced 3w ago

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

PHP Value Object
================

[](#php-value-object)

Just another library to handle Value Objects and prevent the bad habit of Primitive Obsession

[![Latest Version](https://camo.githubusercontent.com/4a52ffaedd8f24af2870596b6a97fd5501439ef218705ba9c2ee88631b9b61d6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f44617669644761726369614361742f7068702d76616c75652d6f626a6563742e7376673f7374796c653d666c61742d737175617265)](https://github.com/DavidGarciaCat/php-value-object/releases)[![Build Status](https://camo.githubusercontent.com/37bf89e469991b2648e0f289426988e8180ac94305b52cda27017f38b9530468/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f44617669644761726369614361742f7068702d76616c75652d6f626a6563742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidGarciaCat/php-value-object)[![Code Coverage](https://camo.githubusercontent.com/f07a50fa1144268f2cc2e8f50965cd89cb9454a7e875a6a93410017d30c3787b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f44617669644761726369614361742f7068702d76616c75652d6f626a6563742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidGarciaCat/php-value-object)[![Quality Score](https://camo.githubusercontent.com/dd32e4994e0929d3daf31c826b69e8c57b76230435c1efbc3d9b11aad67e4af1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f44617669644761726369614361742f7068702d76616c75652d6f626a6563742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidGarciaCat/php-value-object)[![Total Downloads](https://camo.githubusercontent.com/0c3910a67661d98d8ec3ca8ed92e17f810eaa07a1292984ebc55a9ea67130713/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f44617669644761726369614361742f7068702d76616c75652d6f626a6563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/DavidGarciaCat/php-value-object)

Changelog
---------

[](#changelog)

All notable changes to this project will be documented in [this ChangeLog file](CHANGELOG.md).

Install
-------

[](#install)

Require the vendor with Composer:

```
composer require david-garcia/value-object
```

Usage
-----

[](#usage)

Make sure you are loading the Composer autoload:

```
require 'vendor/autoload.php';
```

Don't forget adding the use statement for each one of the value objects you need to use:

```
// Example for StringValue
use DavidGarcia\ValueObject\Primitive\StringValue;
```

All value objects have a static `create()` method:

```
StringValue::create('qwerty');
```

The first argument is the value to be wrapped by the value object. The second argument allows you to `statically cache` the value object, so you can instantiate twice an object with the same value but the system will create it just once:

```
$stringValue1 = StringValue::create('qwerty', true);
$stringValue2 = StringValue::create('qwerty', true);

if ($stringValue1 === $stringValue2) {
    // TRUE
    // It's the same object, so it goes inside this conditional
}

$stringValue3 = StringValue::create('qwerty');
$stringValue4 = StringValue::create('qwerty');

if ($stringValue3 === $stringValue4) {
    // FALSE
    // Although they have the same value, the system has created two different objects
}
```

Null values always hold a `null` value:

```
// `NullValue` does not expect any argument
$nullValue = NullValue::create();
```

All value objects have a `getValue()` method to expose the value:

```
$stringValue = StringValue::create('qwerty');
$stringValue->getValue(); // Returns 'qwerty'
```

The `StringValue` value object and any other that extends from this one can use the `__toString` magic method to return the string value, as an alternative to the `getValue()` method:

```
$stringValue = StringValue::create('qwerty');
(string) $stringValue; // Returns 'qwerty'
```

All value objects (except `NullValue`) have an `equals()` method that compares the content of two value objects of the same type:

```
$stringValue1 = StringValue::create('qwerty', true);
$stringValue2 = StringValue::create('qwerty', true);

if ($stringValue1->equals($stringValue2)) {
    // TRUE
    // We ignore the fact that is a cached object, as we compare the value
}

$stringValue3 = StringValue::create('qwerty');
$stringValue4 = StringValue::create('qwerty');

if ($stringValue3->equals($stringValue4)) {
    // TRUE
    // We have a match for the values, so even if we handle two different objects,
    // their values are equal
}
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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 ~1 days

Total

2

Last Release

1967d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62c1db3c19dedf826fe3b41a2fa2df2cc65ec69bd0f388b9854c624e85af5fa4?d=identicon)[DavidGarciaCat](/maintainers/DavidGarciaCat)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/david-garcia-value-object/health.svg)

```
[![Health](https://phpackages.com/badges/david-garcia-value-object/health.svg)](https://phpackages.com/packages/david-garcia-value-object)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M732](/packages/sylius-sylius)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5275.9M119](/packages/symplify-monorepo-builder)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k13](/packages/tempest-framework)[phpactor/phpactor

PHP refactoring and intellisense tool for text editors

1.9k17.1k1](/packages/phpactor-phpactor)[phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

12525.9M148](/packages/phpdocumentor-reflection)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

54681.3k17](/packages/solspace-craft-freeform)

PHPackages © 2026

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