PHPackages                             martindilling/basicvalueobjects - 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. martindilling/basicvalueobjects

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

martindilling/basicvalueobjects
===============================

A collection of basic value objects.

0.2.2(11y ago)119MITPHPPHP &gt;=5.5.0

Since Feb 10Pushed 11y ago1 watchersCompare

[ Source](https://github.com/martindilling/basicvalueobjects)[ Packagist](https://packagist.org/packages/martindilling/basicvalueobjects)[ Docs](https://github.com/martindilling/basicvalueobjects)[ RSS](/packages/martindilling-basicvalueobjects/feed)WikiDiscussions master Synced 1mo ago

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

Basic Value Objects
===================

[](#basic-value-objects)

[![Latest Version](https://camo.githubusercontent.com/8b698c8867a97e3df3342e5c8b130f2d80f4cac1ab6504bf5b2f3b346b04931e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6d617274696e64696c6c696e672f626173696376616c75656f626a656374732e7376673f7374796c653d666c61742d737175617265)](https://github.com/martindilling/basicvalueobjects/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/37bb2574b83d326ec123798125c21c28f0d7bb03ca911b1cd9a48353d9819488/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d617274696e64696c6c696e672f626173696376616c75656f626a656374732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/martindilling/basicvalueobjects)[![Coverage Status](https://camo.githubusercontent.com/c2d385350675ce69d43cddfc4d0681d1957acc004309e885b13f8458c1f64ff2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d617274696e64696c6c696e672f626173696376616c75656f626a656374732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/martindilling/basicvalueobjects/code-structure)[![Quality Score](https://camo.githubusercontent.com/fab5d10c707f1465b3d791453292ea92279bd6ab0266c4aa75d459bf68b1a192/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d617274696e64696c6c696e672f626173696376616c75656f626a656374732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/martindilling/basicvalueobjects)[![Total Downloads](https://camo.githubusercontent.com/7d28e4b77cf25a9b045c9c0cfd05e1a7335909f0c5fef9ece16cc226c9404ecc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617274696e64696c6c696e672f626173696376616c75656f626a656374732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/martindilling/basicvalueobjects)[![SensioLabsInsight](https://camo.githubusercontent.com/51184c42fc3992504e78736f0cb494cb5d15c2d76d39c2d1a9e02f7ecf4acfdd/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f37303532666133342d633637332d346230362d396337362d3361376436646564376462392e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/7052fa34-c673-4b06-9c76-3a7d6ded7db9)

A small collection of the most basic value objects. These can help make your code more expressive, and save some manual validation.

Install
-------

[](#install)

All the available versions is visible [on Packagist](https://packagist.org/packages/martindilling/basicvalueobjects).

Via Composer

```
$ composer require martindilling/basicvalueobjects
```

Usage
-----

[](#usage)

Using these value objects you can type-hint method arguments to make it more sure the arguments will be given in the right format.

In this example the fields will hold instances of the value objects.

```
use BasicValueObjects\String;
use BasicValueObjects\Integer;
use BasicValueObjects\Boolean;

class CrewMember
{
    /** @var \BasicValueObjects\String */
    private $firstname;

    /** @var \BasicValueObjects\String */
    private $lastname;

    /** @var \BasicValueObjects\Integer */
    private $age;

    /** @var \BasicValueObjects\Boolean */
    private $captain;

    function __construct(String $firstname, String $lastname, Integer $age, Boolean $captain)
    {
        $this->firstname = $firstname;
        $this->lastname  = $lastname;
        $this->age       = $age;
        $this->captain   = $captain;
    }
}

$person = new CrewMember(
    new String('Malcolm'),
    new String('Reynolds'),
    new Integer(49),
    Boolean::true()
);
```

If you don't want the fields on the object to hold the instances but want the type-hinting, you can just assign the native value of the value object to the fields:

```
use BasicValueObjects\String;
use BasicValueObjects\Integer;
use BasicValueObjects\Boolean;

class CrewMember
{
    /** @var string */
    private $firstname;

    /** @var string */
    private $lastname;

    /** @var int */
    private $age;

    /** @var bool */
    private $captain;

    function __construct(String $firstname, String $lastname, Integer $age, Boolean $captain)
    {
        $this->firstname = $firstname->native();
        $this->lastname  = $lastname->native();
        $this->age       = $age->native();
        $this->captain   = $captain->native();
    }
}

$person = new CrewMember(
    new String('River'),
    new String('Tam'),
    new Integer('28'),
    Boolean::false()
);
```

Demonstration of how to work with the value objects:

```
// String
$shiny = new String("Everything's shiny, Cap'n. Not to fret.");
$fool  = new String("Oh, she'll fool ya.");

$shiny->native();       // (string) Everything's shiny, Cap'n. Not to fret.
$fool->__toString();    // (string) Oh, she'll fool ya.
$shiny->equals($fool);  // (bool) false

// Integer
$integer1 = new Integer(42);
$integer2 = new Integer(37);

$integer1->native();           // (integer) 42
$integer2->__toString();       // (string) 37
$integer1->equals($integer2);  // (bool) false

// Boolean
$boolean1 = new Boolean(true);
$boolean2 = new Boolean(Boolean::TRUE);
$boolean3 = Boolean::false();

$boolean1->native();           // (bool) true
$boolean2->__toString();       // (string) true
$boolean1->equals($boolean2);  // (bool) true
$boolean1->equals($boolean3);  // (bool) false
```

Testing
-------

[](#testing)

```
$ phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Martin Dilling-Hansen](https://github.com/martindilling)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

5

Last Release

4101d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/58a08b906afaef2d8891c0195c6ce4454d359854d2f0e126ff204cd02d158876?d=identicon)[martindilling](/maintainers/martindilling)

---

Top Contributors

[![martindilling](https://avatars.githubusercontent.com/u/1018838?v=4)](https://github.com/martindilling "martindilling (9 commits)")

---

Tags

stringintegervalue objectsdddfloatboolean

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/martindilling-basicvalueobjects/health.svg)

```
[![Health](https://phpackages.com/badges/martindilling-basicvalueobjects/health.svg)](https://phpackages.com/packages/martindilling-basicvalueobjects)
```

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M276](/packages/brick-math)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[opis/string

Multibyte strings as objects

7120.9M7](/packages/opis-string)[danog/phpstruct

PHP implementation of python's struct module.

1110.1k](/packages/danog-phpstruct)[phootwork/lang

Missing PHP language constructs

1224.8M8](/packages/phootwork-lang)[cviebrock/eloquent-typecast

Trait for Eloquent models to force type-casting on retrieved values

2468.0k](/packages/cviebrock-eloquent-typecast)

PHPackages © 2026

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