PHPackages                             hradigital/php-datatypes - 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. hradigital/php-datatypes

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

hradigital/php-datatypes
========================

Easy way to build up and sanitize your application objects.

2.0.6(4y ago)17MITPHPPHP ^7.4||^8.0CI failing

Since May 24Pushed 4y ago2 watchersCompare

[ Source](https://github.com/HRADigital/php-datatypes)[ Packagist](https://packagist.org/packages/hradigital/php-datatypes)[ RSS](/packages/hradigital-php-datatypes/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (0)

PHP Datatypes
=============

[](#php-datatypes)

Master branch build status
--------------------------

[](#master-branch-build-status)

[![Build](https://camo.githubusercontent.com/2683a414f933786e756447b3fd3db2ef4328b081fe53112980eaab44009b19a6/68747470733a2f2f696d672e736869656c64732e696f2f636972636c6563692f6275696c642f6769746875622f4852414469676974616c2f7068702d6461746174797065732e737667)](https://github.com/HRADigital/php-datatypes)[![Coverage](https://camo.githubusercontent.com/a3d2360e3de0fd45c230d56b9ef4c310f3fed6a4353292db8293e723c52dc166/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f4852414469676974616c2f7068702d6461746174797065732e737667)](https://github.com/HRADigital/php-datatypes)[![Quality](https://camo.githubusercontent.com/ef56e880ff050fc2513b8dc458f74fdfefd548c07aaab580bd75bd6dd9d9e072/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6465303331353532303863363431393638393938343834353863326365643861)](https://www.codacy.com/gh/HRADigital/php-datatypes/dashboard?utm_source=github.com&utm_medium=referral&utm_content=HRADigital/php-datatypes&utm_campaign=Badge_Grade)[![Downloads](https://camo.githubusercontent.com/8f13d98f5616e5f039f274713fa596bd82f5fbf6a75f669a4a11af43f6ae2159/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f4852414469676974616c2f7068702d6461746174797065732f746f74616c2e737667)](https://github.com/HRADigital/php-datatypes)[![Licence](https://camo.githubusercontent.com/904f8fa58794676e0e6c43e8b4247040d6e360b7fda1d2b59d94e171fed33909/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4852414469676974616c2f7068702d6461746174797065732e737667)](https://github.com/HRADigital/php-datatypes)[![Version](https://camo.githubusercontent.com/65de9263e903cf7236b1995f71a4c0ab2afbcbac4affa4103d87b238e88056fb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f4852414469676974616c2f7068702d6461746174797065732e737667)](https://github.com/HRADigital/php-datatypes)[![PHP](https://camo.githubusercontent.com/1a43181c5444a940ced684b26ee7e2e2c4d078922240f27c65c0c317daecadc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6872616469676974616c2f7068702d6461746174797065732e737667)](https://github.com/HRADigital/php-datatypes)

Code Usage
----------

[](#code-usage)

This package is mean to provide you an easy way to do this (*and much more*):

```
$user = new User([
    'id' => 123,
    'active' => true,
    'name' => ' John Doe ',
]);

echo $user->getId(); // (int) 123
echo $user->isActive(); // (bool) true
echo $user->getName(); // Prints ' John Doe '
echo $user->getName()->trim()->toUpper()->replace(' ', '-'); // Prints 'JOHN-DOE'
echo $user->getName(); // Prints ' John Doe ' again, as Attribute is immutable.
```

... just by building your object like this:

```
class User extends AbstractValueObject
{
    use HasPositiveIntegerIDTrait,
        HasActiveTrait,
        HasNameTrait;
}
```

Also, out-of-box, it will allow you to do the following:

```
$user = new User([
    'id' => 123,
    'active' => true,
    'name' => ' John Doe ',
]);

echo json_encode($user); // {"id":123,"active":true,"name":"John Doe"}

$serialized = serialize($user);
$otherUser = unserialize($serialized);

printf($otherUser->toArray());
/*
[
    'id' => 123,
    'active' => true,
    'name' => 'John Doe',
]
*/
```

... and much more. This will leave your objects clean from repetitive state management code, which frees you to implement your business logic in them.

In order to learn more about the code, please go [here](https://github.com/HRADigital/php-datatypes/blob/master/src/ValueObjects).

About
-----

[](#about)

**PHP Datatypes** is meant to provide an easy way to create your Value Objects/Entities/Aggregates, in a fast and platform agnostic way, that promotes:

- Code reusability
- Data normalization
- Type hint enforcement
- Full data serializing
- No 3rd party dependency apart from PHP. Clean/Self reliant project.

An Aggregate/Entity/ValueObject that extends [AbstractValueObject](https://github.com/HRADigital/php-datatypes/blob/master/src/ValueObjects/AbstractValueObject.php)will be built using predefined/tested [Traits](https://github.com/HRADigital/php-datatypes/tree/master/src/Traits/Entities) for each of the class attributes, leaving your class definition cleaned/free for your business logic implementation.

This will also allow you to reuse/load your objects with data that can come from a Database, Webservice, Event payload, etc...

Getters/Accessors for class attributes will return ValueObjects instead of primitive types, as much as possible. All these datatypes will also be included in the package, as it doesn't have any dependencies apart from, PHP itself.

To learn how to use this package, please go to [AbstractValueObject](https://github.com/HRADigital/php-datatypes/blob/master/src/ValueObjects/) documentation.

### Inspiration

[](#inspiration)

Some of the projects that inspired this one, are mainly [Nikita Popov's Scalar Objects](https://github.com/nikic/scalar_objects), but also [Martin Helmich's Scalar Classes](https://github.com/martin-helmich/php-scalarclasses/) and [Michael Hall's Datatypes](https://github.com/themichaelhall/datatypes/).

Due to the "*No 3rd party dependency*" rule, this package will use some simplified versions of more popular datatypes. Some examples are:

- [synfony/string](https://github.com/symfony/string), for String related manipulations.
- [nesbot/carbon](https://github.com/briannesbitt/Carbon), for DateTime manipulations.
- ...

Requirements &amp; Installation
-------------------------------

[](#requirements--installation)

- PHP &gt;= 7.4||8.\*

```
composer require hradigital/php-datatypes
```

Usage
-----

[](#usage)

For more information about how to to use these Datatypes, please see the project's **usage notes** and some implementation examples in [here](src/).

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

[](#contributing)

Contributing to the project is easy and contributions are welcomed and appreciated.

It's obviously harder to maintain the project alone, but efforts will be made to keep and improve it, as I plan to use it as a dependency in other projects.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity71

Established project with proven stability

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

Recently: every ~1 days

Total

13

Last Release

1508d ago

Major Versions

0.1.3 → 1.0.02019-05-25

1.0.1 → 2.0.02022-03-22

PHP version history (2 changes)0.1.0PHP ^7.2

2.0.0PHP ^7.4||^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/34803364423357ae62828a472022dc7af10a4b64833418f8b8f4e905f6fa3fc8?d=identicon)[hradigital](/maintainers/hradigital)

---

Top Contributors

[![HRADigital](https://avatars.githubusercontent.com/u/8511557?v=4)](https://github.com/HRADigital "HRADigital (11 commits)")

---

Tags

phpentityDomain Driven Designvalue objectsddddomainentitiesaggregatesdatatypesscalar-objectsimmutable objectsmutable objects

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/hradigital-php-datatypes/health.svg)

```
[![Health](https://phpackages.com/badges/hradigital-php-datatypes/health.svg)](https://phpackages.com/packages/hradigital-php-datatypes)
```

###  Alternatives

[treshugart/model

Model is a simple, lightweight and easy-to-use Domain Driven Entity framework.

171.4k](/packages/treshugart-model)[devco/model

Model is a simple, lightweight and easy-to-use Domain Driven Entity framework.

171.4k](/packages/devco-model)

PHPackages © 2026

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