PHPackages                             estvoyage/value - 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. estvoyage/value

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

estvoyage/value
===============

A set of whole value to avoid using native PHP type, see http://c2.com/cgi/wiki?ValueObject for more information

3426PHP

Since Apr 6Pushed 11y ago2 watchersCompare

[ Source](https://github.com/estvoyage/value)[ Packagist](https://packagist.org/packages/estvoyage/value)[ RSS](/packages/estvoyage-value/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

*estvoyage\\value* [![Build Status](https://camo.githubusercontent.com/eb4b4bef0cd0361132b838ab718b963941d97f9d2654d7fa76b1ff235e3c325f/68747470733a2f2f7472617669732d63692e6f72672f657374766f796167652f76616c75652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/estvoyage/value) [![Coverage Status](https://camo.githubusercontent.com/1a690ac8896f45d84fd273891964788e4b457538d43389265586df8688b4f1be/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f657374766f796167652f76616c75652f62616467652e706e67)](https://coveralls.io/r/estvoyage/value)
==========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#estvoyagevalue--)

A set of whole value for PHP
----------------------------

[](#a-set-of-whole-value-for-php)

Beside using the handful of primitive type offered by PHP (floats, integers, strings, boolean, datetime), you will make and use new objects that represent the meaningful quantities of your business.
These values (like currency, credit card numbers, zip code, firstname, lastname, calendar period or telephone number) will carry whole, useful chunks of information from the user-interface to the domain model.
But often in early stages of development you make decisions about representing simple facts using primitive type…
And as development proceeds you realize that those simple items aren't so simple anymore: A telephone number may be represented as a string for a while, but later you realize that the telephone needs special behavior for formatting, extracting the area code, and the like.
So it must be interesting to use object to quantify your domain model and use these values as the arguments of your methods very early.

This set provide currently base classes for:

- string
- integer
- unsigned integer
- float
- unsigned float

All instances of these classes are [immutable](http://c2.com/cgi/wiki?ValueObjectsShouldBeImmutable), so if you try to set or unset one of their properties, a `logicException` will be throwed.
To access the underlying value, use property `asString` for `string`, `asInteger` for `integer` and `asFloat` for `float`.
All of these classes are abstract, so you should extends them to quantify your domain:

```
