PHPackages                             elegant-php/types - 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. elegant-php/types

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

elegant-php/types
=================

PHP types as objects

1.0.0(2y ago)02MPL-2.0PHPPHP &gt;=8.1

Since Jan 11Pushed 2y agoCompare

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

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

PHP types as objects
====================

[](#php-types-as-objects)

[![tests](https://camo.githubusercontent.com/0bc86b02144f5feb4f42c7332340644aab1b5745a1a4e54ac88d14ee8a04a267/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656c6567616e742d7068702f74797065732f72656c656173652e796d6c)](https://github.com/elegant-php/types/actions/workflows/release.yml)[![version](https://camo.githubusercontent.com/ac48bf404c46158225261d6312a1c7664b4d66172f6621db6f21545a4f18aeca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6567616e742d7068702f7479706573)](https://packagist.org/packages/elegant-php/types)[![downloads](https://camo.githubusercontent.com/8260cceadca651709a59432e979b5f4fe8e328fb8cf31898d1639674537cf580/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c6567616e742d7068702f7479706573)](https://packagist.org/packages/elegant-php/types)[![license](https://camo.githubusercontent.com/4d5aa66f4388ca85a130e3bfa7bf90fdfa18b448c71a935c7c6fc2cb720cd1c6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f656c6567616e742d7068702f7479706573)](/LICENSE)

This package provides the ability to work with types as objects.

Available types:

- Integer
- String
- Float
- Boolean
- Array

Installation
------------

[](#installation)

`composer require elegant-php/types`

Usage
-----

[](#usage)

### Use predefined classes and contracts

[](#use-predefined-classes-and-contracts)

```
final class AuthorizedUser implements User
{
  public function __construct(
    private readonly StringType $name
  ) { }
}

$user = new AuthorizedUser(new DefaultString('my user'));
```

### Implement type contracts

[](#implement-type-contracts)

```
final class UserName extends StringType
{
  public function __construct(
    private readonly string $name
  ) { }

  public function value(): string
  {
    return strtolower($this->name);
  }
}
```

### Compare types

[](#compare-types)

```
$first = new DefaultString('first');
$second = new DefaultString('first');

var_dump($first->equals($second));

// bool(false)
```

### Type casting

[](#type-casting)

```
$id = new StringAsInteger('123');

var_dump($id->value());

// int(123)
```

---

[Release notes](/CHANGELOG.md)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community6

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

Unknown

Total

1

Last Release

858d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1f439b4337e659c715b5c5ad4673a35b4787c550fcafd9b1d6011a9aed661a5?d=identicon)[vhood](/maintainers/vhood)

---

Top Contributors

[![vhood](https://avatars.githubusercontent.com/u/55533574?v=4)](https://github.com/vhood "vhood (12 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/elegant-php-types/health.svg)

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

###  Alternatives

[hillholliday/craft-user-manual

Craft User Manual allows developers (or even content editors) to provide CMS documentation using Craft's built-in sections (singles, channels, or structures) to create a `User Manual` or `Help` section directly in the control panel.

8472.1k1](/packages/hillholliday-craft-user-manual)[laravolt/semantic-form

Semantic UI form helpers

5213.0k2](/packages/laravolt-semantic-form)

PHPackages © 2026

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