PHPackages                             best-served-cold/phalue-objects - 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. best-served-cold/phalue-objects

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

best-served-cold/phalue-objects
===============================

Phalue Objects - PHP Value Objects

v0.0.11-alpha(9y ago)6151[1 PRs](https://github.com/nark3d/PhalueObjects/pulls)2MITPHPPHP &gt;=5.6

Since Sep 23Pushed 9y ago2 watchersCompare

[ Source](https://github.com/nark3d/PhalueObjects)[ Packagist](https://packagist.org/packages/best-served-cold/phalue-objects)[ Docs](http://bestservedcold.com)[ RSS](/packages/best-served-cold-phalue-objects/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (8)Versions (13)Used By (2)

PhalueObjects
=============

[](#phalueobjects)

[![Build Status](https://camo.githubusercontent.com/e82c0d0c5749237341953126d22dd268aee3194946b981c05ca916cb6e0e273e/68747470733a2f2f7472617669732d63692e6f72672f6e61726b33642f5068616c75654f626a656374732e737667)](https://travis-ci.org/nark3d/PhalueObjects)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/78338a3e105cb01fa9fd377f71471c69dd537adf00d06d78741fca8b6194678e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e61726b33642f7068616c75656f626a656374732f6261646765732f7175616c6974792d73636f72652e706e673f733d39373935363763326437393166666265616231323737376336306338656462383637373664646363)](https://scrutinizer-ci.com/g/nark3d/phalueobjects/)[![Code Coverage](https://camo.githubusercontent.com/f79dd8120d41d8d6f63e17cc9e7851b84607bea5b3d6005ea18b8a5ce9f9b3e5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e61726b33642f7068616c75656f626a656374732f6261646765732f636f7665726167652e706e673f733d35396464346131343234313261396463643938393837303631306631633966383963313963663438)](https://scrutinizer-ci.com/g/nark3d/phalueobjects/)[![SensioLabsInsight](https://camo.githubusercontent.com/f301659981c6b629bc7f11c672bc1806d613bf6d61b9883cf623ffbc93d6f1bb/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f35383230666366642d383539332d346237362d393961362d3339376239346364363539632f6d696e692e706e67)](https://insight.sensiolabs.com/projects/5820fcfd-8593-4b76-99a6-397b94cd659c)

A generic set of PHP Value Objects for use in any project.

[Wikipedia](https://en.wikipedia.org/wiki/Domain-driven_design)

> When people exchange business cards, they generally do not distinguish between each unique card; they only are concerned about the information printed on the card. In this context, business cards are value objects.

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Philosophy](#philosophy)
- Documents
    - [Format](src/Format/README.md)

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

[](#installation)

```
composer require best-served-cold/phalue-objects
```

Philosophy
----------

[](#philosophy)

To make this code consistent, we've stuck to a certain set of restrictions:

### Rules

[](#rules)

- [**Must** be immutable](#must-be-immutable)
- [**Must** contain one value](#must-contain-one-value)
- [**Can** instantiate new object from value](#can-instantiate-new-object-from-value)
- [**Can** be created from multiple arguments](#can-be-created-from-multiple-arguments)
- [**Can** be equal regardless of object](#can-be-equal-regardless-of-object)
- [**Must** have a zero lifespan](#must-have-a-zero-lifespan)

*Disclaimer: This is my interpretation of "The rules".*

#### Must be immutable

[](#must-be-immutable)

The value object's value must be set at the time of construction. At no point should the value be mutated within the object.

#### Must contain one value

[](#must-contain-one-value)

The value object can only be constructed from one value, this can be any of the following types:

- boolean
- integer
- float/double
- string
- array
- object
- resource
- null

#### Can instantiate new object from value

[](#can-instantiate-new-object-from-value)

Rather than mutating, a new object can be instantiated from an existing one.

Example:

```
//...
public function double()
{
    return new static($this->getValue() * 2);
}
...//
```

#### Can be created from multiple arguments

[](#can-be-created-from-multiple-arguments)

Instead of an object having multiple object properties, it should be created from multiple arguments.

Example:

```
//...
public static function fromVars($one = 1, $two = 2, $three = 3)
{
    return new static([$one, $two, $three]);
}
...//
```

#### Can be equal regardless of object

[](#can-be-equal-regardless-of-object)

The type of a value object is irrelevant to equality:

Example:

```
//...
$bob = $stringValueObject->equals($csvValueObject);
...//
```

`$bob` is true where the type and value are equal.

#### Must have a zero lifespan

[](#must-have-a-zero-lifespan)

Value objects must not persist data between run times. For example: no database or session information should be collected from within the object.

Conventions
-----------

[](#conventions)

Follow [PSR-FIG](http://www.php-fig.org/) rules.

### Constructor

[](#constructor)

Example:

```
new SomeClass('value');
```

- **Must** only have one argument of any type

### Creation methods (From)

[](#creation-methods-from)

Example:

```
SomeClass::fromSomeObject($someObject);
```

- **Always** start with "from"
- **Must** be static
- **Can** contain multiple arguments
- **Must** return new static instance

### Conversion methods (To)

[](#conversion-methods-to)

Example:

```
$someObject->toArray();
```

- **Always** start with "to"
- **Must not** be static
- **Must** have zero arguments
- **Must** return new static instance

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.4% 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 ~53 days

Recently: every ~108 days

Total

11

Last Release

3355d ago

PHP version history (3 changes)v0.0.1-alphaPHP &gt;=5.4.0

v0.0.9-alphaPHP &gt;=5.5.0

v0.0.10-alphaPHP &gt;=5.6

### Community

Maintainers

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

---

Top Contributors

[![nark3d](https://avatars.githubusercontent.com/u/2162621?v=4)](https://github.com/nark3d "nark3d (232 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (19 commits)")

---

Tags

domain-driven-designphpphp-value-objectsusablevalue-objectvalueobjectvalue objectsimmutablePhalueObjectsBest Served Cold

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/best-served-cold-phalue-objects/health.svg)

```
[![Health](https://phpackages.com/badges/best-served-cold-phalue-objects/health.svg)](https://phpackages.com/packages/best-served-cold-phalue-objects)
```

###  Alternatives

[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

96374.6k23](/packages/friendsoftypo3-content-blocks)[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

344146.0k](/packages/qaribou-immutablephp)[innmind/immutable

Immutable PHP primitive wrappers

75218.0k74](/packages/innmind-immutable)[serendipity_hq/component-value-objects

A set of value objects to manage simple and composite values

20558.6k4](/packages/serendipity-hq-component-value-objects)[rtlopez/decimal

An object oriented immutable arbitrary-precision arithmetic library for PHP

27262.8k2](/packages/rtlopez-decimal)

PHPackages © 2026

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