PHPackages                             grido/primitive-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. grido/primitive-objects

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

grido/primitive-objects
=======================

Bring a bit of true OOP to your PHP code by using primitives (strings, numbers, arrays) as a first-class objects :)

v0.1.3(10y ago)119GPL-3.0PHPPHP &gt;=5.3.0

Since Dec 16Pushed 10y ago1 watchersCompare

[ Source](https://github.com/dobryakov/php-primitive-objects)[ Packagist](https://packagist.org/packages/grido/primitive-objects)[ RSS](/packages/grido-primitive-objects/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (5)Used By (0)

About
-----

[](#about)

Bring a bit of "true OOP" to your PHP code by using primitives (strings, numbers, arrays) as a first-class objects.

[![Build Status](https://camo.githubusercontent.com/e8bcdb022f2967ef0cf75f3493817b7bceecf0755a00a42a7dd6cd9ec733d58f/68747470733a2f2f7472617669732d63692e6f72672f646f627279616b6f762f7068702d7072696d69746976652d6f626a656374732e737667)](https://travis-ci.org/dobryakov/php-primitive-objects)

Inspired by
-----------

[](#inspired-by)

*Most of the problems in software engineering occurs by the reason of variables get incorrect values somewhere in your code (c) Erlang authors.*

Why?
----

[](#why)

When you assigned some value to $x somewhere, you always need to check it in several places where $x can be used (in other functions and even other files too). And in case of problems you need to trace your code and find *where* your $x got incorrect value. I think it is much better to be *sure* that you always have a *valid* value inside your $x, anywhere, at any moment, in any line of your code.

```
Simple rule: if you have a variable - it contains a valid value.
Always.

```

When you are expecting several "primitive types" as an arguments to your function, you always need to validate its inside. This is an unefficient way which provides a lot of unusable code. It's much better to validate and operate with them by convention-like principle bringed by true functional languages:

```
Each thing must be an object.

```

Key ideas
---------

[](#key-ideas)

String is an object. Numeric is an object. Array is an object (and it contains objects too). Do you want to write something like this?

```
function doCoolStuff( String $name, Numeric $weight ) {
  // you will get exception if $name is not string, and/or $weight is not numeric,
  // without ANY other checks or validations in your function's body.
}

```

Or, for example:

```
$data->getHistoryOfChanges() // -> [ 'value 1', 'value 2', null, 'value 3' ]

```

Or, maybe:

```
"Person"->pluralize() // -> "People"

```

It may be possible now :)

Current features
----------------

[](#current-features)

- String object
- Numeric object
- Array object (Traversable)
- Several constraints (numeric, min, max, string)
- History of value changes

How it works
------------

[](#how-it-works)

Look at the code examples in test/PrimitiveObjectsTest.php to understand.

All validations and constraints incapsulated into object classes, and in case of incorrect data you will get an exception *before* it comes to your function's body.

You can create "immutable objects" by declining data changes if value is already set.

You can construct your own "types" of objects by combining different constraints even in runtime. For example, you can create:

- array of strings,
- with constraint of 10 items max,
- and with constraint each item to be a string with length in range 1..255,
- and begins with capitalized letter,
- and so on :)

Caveats
-------

[](#caveats)

This approach always will be slower than real primitives in highload calculations.

License
-------

[](#license)

General Public License.

TODO
----

[](#todo)

- Any suggestions?

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Total

4

Last Release

3848d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3643717?v=4)[grido](/maintainers/grido)[@grido](https://github.com/grido)

---

Top Contributors

[![dobryakov](https://avatars.githubusercontent.com/u/973470?v=4)](https://github.com/dobryakov "dobryakov (46 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/grido-primitive-objects/health.svg)

```
[![Health](https://phpackages.com/badges/grido-primitive-objects/health.svg)](https://phpackages.com/packages/grido-primitive-objects)
```

PHPackages © 2026

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