PHPackages                             mmagyar/typage-php - 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. mmagyar/typage-php

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

mmagyar/typage-php
==================

Easily validate data with type classes

0.3.4(10y ago)060[2 issues](https://github.com/mmagyar/typage-php/issues)MITPHPPHP &gt;=5.4

Since Dec 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/mmagyar/typage-php)[ Packagist](https://packagist.org/packages/mmagyar/typage-php)[ Docs](https://github.com/mmagyar/typage-php)[ RSS](/packages/mmagyar-typage-php/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (6)Used By (0)

typage-php
==========

[](#typage-php)

### Easily validate data with type classes

[](#easily-validate-data-with-type-classes)

With a single definition you can validate your data, be that for input, output or testing.

With the same definition you can generate a description in a valid, human readable json format. It's on the road map to be able to turn those jsons back to type checking instances

In case a checking fails you get an exception with an informative error message where the error happened and what went wrong.

Example:

`Value named: request:myArray[1] with data: "hallo asdf" does not conform to regex: /^\w+$/u`

or:

`Value named: request:myNumber has a value of 55 which is bigger then the maximum: 34.234`

You can easily add your own types by extending the AbstractAny class, or just using the Any class with a validation Closure.

Check out the tests folder, for usage examples, and mess around with it to see how this works.

A tiny exampe on how to use it:

```
$validator = new Object(
    "myNumber0to10"       => new Integer(0, 10),
    "myStringArray"       => new ArrayList(new Text()),
    "singleWord"          => new Text("/^\w+$/u"),
    "optionalNumber"      => new Nullable(new Double()),
    "optionalWithDefault" => new Either(new Text(), "Hello World")
);

$validatedData = $validator->check($input, "request");
```

### Why this instead of JSON schema?

[](#why-this-instead-of-json-schema)

Above all that JSON schema provides, this library provides:

- All properties are Required by default
- Error handling is automatically done with exceptions, by default, no need to check the result for errors.
- Null is not handled as meaningful data, a property must be explicitly declared Nullable.
- Easy to extend\*.
- It's safer and easier to declare the type annotations, you always know what are the possible properties from the constructor's signature.
- It's in the same language and doesn't necessarily require a separate file.
- You can pass around validators in you application, without any concern, since they are regular immutable php Objects.
- We can generate a JSON schema from the definition\*\* ;)

\* You can just grab the Any class and write a validator function, since sometimes you have to validate against the database. You can easily extend AbstractAny class, to create you own types.

\*\*Syntax slightly differs

###  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

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

Total

5

Last Release

3801d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2776781?v=4)[Magyar Máté](/maintainers/mmagyar)[@mmagyar](https://github.com/mmagyar)

---

Top Contributors

[![mmagyar](https://avatars.githubusercontent.com/u/2776781?v=4)](https://github.com/mmagyar "mmagyar (15 commits)")

---

Tags

typevalidationtypesafecheckingTypechecking

### Embed Badge

![Health badge](/badges/mmagyar-typage-php/health.svg)

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

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k510.9M898](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k156.0M487](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

6.0k39.0M407](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k38.3M139](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

65141.2M263](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

9315.3M63](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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