PHPackages                             ryanwhitman/php-values - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. ryanwhitman/php-values

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

ryanwhitman/php-values
======================

PHP Values

v1.6.0(2mo ago)05251MITPHPPHP &gt;=7.4 &lt;8.6

Since Feb 20Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/RyanWhitman/php-values)[ Packagist](https://packagist.org/packages/ryanwhitman/php-values)[ Docs](https://github.com/RyanWhitman/php-values)[ RSS](/packages/ryanwhitman-php-values/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (10)Versions (9)Used By (1)

PHP Values
==========

[](#php-values)

[![Latest Version on Packagist](https://camo.githubusercontent.com/38feeb9ecfc549d3e9113064163e7ba5f085a0ea5ec8f5fc7a6c32ee9eb9b940/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7279616e776869746d616e2f7068702d76616c7565732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryanwhitman/php-values) [![PHP from Packagist](https://camo.githubusercontent.com/53660d0d2ca9599a67b089777e894dcddbcf1fa276acc615c313fe6abed02fae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7279616e776869746d616e2f7068702d76616c7565733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryanwhitman/php-values) [![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE) [![Total Downloads](https://camo.githubusercontent.com/ae306ba54889964d5d3a319eafcd543a32d0a62db6ac821d62001300e69c9041/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7279616e776869746d616e2f7068702d76616c7565732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryanwhitman/php-values)

PHP Values is a tool for creating immutable value objects in PHP. A value object intakes a raw value, transforms it, validates it, and can be used consistently and dependably across your application.

For instance, suppose you need an email address when creating a user. You can write it more traditionally like this:

```
public function createUser(string $email)
{
    // perform sanitation and validation on email before using
}
```

But it's more optimal to write it like this:

```
use RyanWhitman\PhpValues\Email;

public function createUser(Email $email)
{
    // email has already been sanitized and validated and is ready for use
}
```

Install
-------

[](#install)

You should install the package via composer:

```
composer require ryanwhitman/php-values
```

Example
-------

[](#example)

Start by creating a Value class. For instance, a Value class for an email address:

```
