PHPackages                             guym4c/prop-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. guym4c/prop-types

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

guym4c/prop-types
=================

Complete PHP port of React PropTypes (fork of prezly/prop-types)

v1.0.1(6y ago)013.3k2[1 PRs](https://github.com/guym4c/prop-types-php/pulls)1MITPHPPHP &gt;=7.4

Since Dec 27Pushed 3y agoCompare

[ Source](https://github.com/guym4c/prop-types-php)[ Packagist](https://packagist.org/packages/guym4c/prop-types)[ RSS](/packages/guym4c-prop-types/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (5)Used By (1)

PropTypes.php
=============

[](#proptypesphp)

**A fork of [prezly/prop-types-php](https://github.com/prezly/prop-types-php). Please consider using the original package**

Complete PHP port of [React PropTypes](https://github.com/facebook/prop-types).

Runtime type checking for complex properties structures.

You can use prop-types to document the intended types of properties passed into your code. PropTypes will check props passed to your functions against those definitions, and throw an error if they don’t match.

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

[](#installation)

```
composer require guym4c/prop-types

```

Credit
------

[](#credit)

This is a fork of [prezly/prop-types-php](https://github.com/prezly/prop-types-php).

This package adds:

- Iterable proptype
- Callable proptype
- Number float/int shorthand proptype
- PHP7.4

Usage
-----

[](#usage)

PropTypes was originally exposed as part of the React core module, and is commonly used with React components. We've tried to bring the familiarity of React PropTypes into PHP. Here is an example of using PropTypes with a PHP function, which also documents the different validators provided.

You can call `PropTypes::check()` to validate an array of props, providing it with a props spec as below:

```
use Guym4c\PropTypes\Exception\PropTypeException;
use Guym4c\PropTypes\PropTypes;

[
    // You can declare that a prop has a specific type.
    // By default, these are all optional.
    'optionalArray' => PropTypes::array(),
    'optionalBool' => PropTypes::bool(),
    'optionalFunction' => PropTypes::callable(),
    'optionalInteger' => PropTypes::int(),
    'optionalFloat' => PropTypes::float(),
    'optionalIterable' => PropTypes::iterable(),
    'optionalObject' => PropTypes::object(),
    'optionalString' => PropTypes::string(),
    // You can also declare that a prop is an instance of a class.
    // This uses `instanceof` operator.
    'optionalDateTime' => PropTypes::instanceOf(DateTime::class),
    // You can ensure that your prop is limited to specific values
    // by treating it as an enum.
    'optionalEnum' => PropTypes::oneOf(['News', 'Photos']),
    // An object that could be one of many types
    'optionalUnion' => PropTypes::oneOfType([
        PropTypes::string(),
        PropTypes::int(),
        PropTypes::instanceOf(DateTime::class),
    ]),

    // Float or int shorthand
    'optionalNumber' => PropTypes::number(),

    // An array of a certain type
    'optionalArrayOf' => PropTypes::arrayOf(PropTypes::int()),

    // You can chain any of the above with `isRequired`
    // to make sure an error is thrown if the prop isn't provided.

    // An object taking on a particular shape
    'optionalArrayWithShape' => PropTypes::shape([
        'optionalProperty' => PropTypes::string(),
        'requiredProperty' => PropTypes::int()->isRequired(),
    ]),

    // An object with errors on extra properties
    'optionalObjectWithStrictShape' => PropTypes::exact([
        'optionalProperty' => PropTypes::string(),
        'requiredProperty' => PropTypes::int()->isRequired(),
    ]),

    // A value of any data type (except null)
    'requiredAny' => PropTypes::any()->isRequired(),
    // A value of any data type (including null)
    'requiredNullableAny' => PropTypes::any()->isRequired()->isNullable(),

    // A required property that can be string or null
    'requiredNullableString' => PropTypes::string()->isRequired()->isNullable(),

    // You can also specify a custom validator.
    // It should return a PropTypeException instance if the validation fails.
    'customProp' => PropTypes::callback(
        function (array $props, string $prop_name, string $prop_full_name): ?PropTypeException {
            if (! preg_match('/matchme /', $props[$prop_name])) {
                return new PropTypeException(
                    $prop_name,
                    'Invalid prop `' . $prop_full_name . '` supplied. Validation failed.'
                );
            }
            return null;
        }
    ),
];
```

Difference from React PropTypes
-------------------------------

[](#difference-from-react-proptypes)

1. In this package we've split *required* and *nullable* checks into different traits:

    - *Required* means a property has to be defined in the props object
    - *Nullable* means a property value can be set to `null`

    React PropTypes has less straightforward logic around required, nulls and undefined.
2. As opposed to React PropTypes we don't have a separate checker for null (`PropTypes::null()`). Instead any property can become nullable by calling `->isNullable()` on its checker:

    ```
    [
       'title' => PropTypes::string()->isNullable(),
    ];
    ```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 87.9% 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 ~40 days

Total

4

Last Release

2205d ago

Major Versions

0.2.0 → v1.0.02020-04-26

PHP version history (2 changes)0.1.0PHP &gt;=7.1,&lt;7.4

v1.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/9db8acda212740c63090beab8438300c1e158e824a9642fa49babef315136c4c?d=identicon)[guym4c](/maintainers/guym4c)

---

Top Contributors

[![e1himself](https://avatars.githubusercontent.com/u/370680?v=4)](https://github.com/e1himself "e1himself (58 commits)")[![guym4c](https://avatars.githubusercontent.com/u/2103489?v=4)](https://github.com/guym4c "guym4c (7 commits)")[![anatoliyarkhipov](https://avatars.githubusercontent.com/u/1934180?v=4)](https://github.com/anatoliyarkhipov "anatoliyarkhipov (1 commits)")

### Embed Badge

![Health badge](/badges/guym4c-prop-types/health.svg)

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

###  Alternatives

[voku/stringy

A string manipulation library with multibyte support

1783.8M19](/packages/voku-stringy)[voku/urlify

PHP port of URLify.js from the Django project. Transliterates non-ascii characters for use in URLs.

254.1M7](/packages/voku-urlify)[gregwar/formidable

Formidable, the pragmatic forms library

12062.2k1](/packages/gregwar-formidable)[voku/phonetic-algorithms

Phonetic-Algorithms for fuzzy searching | PHP

1738.4k1](/packages/voku-phonetic-algorithms)

PHPackages © 2026

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