PHPackages                             wookieb/type-check - 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. wookieb/type-check

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

wookieb/type-check
==================

Object oriented way to check the type of data

0.2(12y ago)0892MITPHP

Since Sep 12Pushed 12y ago1 watchersCompare

[ Source](https://github.com/wookieb/type-check)[ Packagist](https://packagist.org/packages/wookieb/type-check)[ RSS](/packages/wookieb-type-check/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (3)Used By (2)

Type check
==========

[](#type-check)

[![Build Status](https://camo.githubusercontent.com/ff33baa113905b4233d5994b5ba88fb611202546578fb9371dca7b6a84e1386f/68747470733a2f2f7472617669732d63692e6f72672f776f6f6b6965622f747970652d636865636b2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/wookieb/type-check)Provide objects oriented and more abstract way to check the type of data.

Note! This library it's not a replacement for functions is\_\* and other type check functions!

Use cases
---------

[](#use-cases)

- type constraints for validators
- definition of type for containers, maps

Install
-------

[](#install)

Via composer

```
    "require": {
        "wookieb/type-check": "0.*"
    }
```

Usage
-----

[](#usage)

```
use Wookieb\TypeCheck\SimpleTypeCheck;
use Wookieb\TypeCheck\ObjectTypeCheck;
use Wookieb\TypeCheck\MultipleTypesCheck;

$string = new SimpleTypeCheck('string'); // accepts only string
$exceptions = new ObjectTypeCheck('\Exception'); // accepts every object that is instance of \Exception
$onlyPureExceptions = new ObjectTypeCheck('\Exception', true); // accepts only \Exception objects (not children)
$multi = new MultipleTypesCheck($string, $exceptions);

$string->isValidType('foo'); // true
$string->isValidType(true); // false
echo $string->getTypeDescription(); // strings

$exceptions->isValidType(new \InvalidArgumentException('foo')); // true
$exceptions->isValidType(null); // false
echo $exceptions->getTypeDescription(); // instances of Exception

$onlyPureExceptions->isValidType(new \Exception('foo')); // true
$onlyPureExceptions->isValidType(new \InvalidArgumentException('foo')); // false
echo $onlyPureExceptions->getTypeDescription(); // objects of class Exception

$multi->isValidType(new \InvalidArgumentException('foo')); // true
$multi->isValidType('foo'); // true
$multi->isValidType(array()); // false
echo $multi->getTypeDescription(); // strings, instances of Exception
```

Memory usage
------------

[](#memory-usage)

You don't need to always create objects of SimpleTypeCheck for common data types. Instead you can use an singleton instance for each basic type.

```
TypeCheck::strings();
TypeCheck::integers();
TypeCheck::floats();
TypeCheck::objects();
TypeCheck::booleans();
TypeCheck::arrays();
TypeCheck::resources();
```

Other type checks
=================

[](#other-type-checks)

TraversableOf
-------------

[](#traversableof)

Allows to check the type of traversable (arrays or instances of \\Traversable interface) elements

```
use Wookieb\TypeCheck\TraversableOf;
use Wookieb\TypeCheck\TypeCheck;

$check = new TraversableOf(TypeCheck::strings());
$check->isValidType(array(1, 'foo', 3)); // false
$check->isValidType(array('foo', 'bar', 'zee')); // true
echo $check->getTypeDescription(); // traversable structures that contains strings
```

CallbackTypeCheck
-----------------

[](#callbacktypecheck)

Uses callback as validation function

```
use Wookieb\TypeCheck\CallbackTypeCheck;

$check = new CallbackTypeCheck(function ($value) {
    return is_array($value) && reset($value) === 'foo';
}, 'arrays with foo string');

$check->isValidType(array('bar')); // false
$check->isValidType(array('foo')); // true
echo $check->getTypeDescription(); // arrays with foo string
```

AllChecks
---------

[](#allchecks)

Value must pass all defined type check

```
use Wookieb\TypeCheck\TraversableOf;
use Wookieb\TypeCheck\TypeCheck;
use Wookieb\TypeCheck\AllChecks;

// narrow the field of "traversable" data types to arrays
$check = new AllChecks(TypeCheck::arrays(), new TraversableOf(TypeCheck::strings()));
$check->isValidType(new ArrayIterator(array('foo', 'bar'))); // false
$check->isValidType(array('foo', 'bar')); // true
echo $check->getTypeDescription(); // arrays traversable structures that contains strings
```

Changelog
=========

[](#changelog)

0.2
---

[](#02)

- added AllChecks, CallbackTypeCheck, TraversableOf

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

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

Total

2

Last Release

4626d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5596087fec711d58384b3d8f8d80e71f49f5a4186a67b14fcf2fc8462924289b?d=identicon)[wookieb](/maintainers/wookieb)

---

Top Contributors

[![wookieb](https://avatars.githubusercontent.com/u/542596?v=4)](https://github.com/wookieb "wookieb (5 commits)")

---

Tags

typecheckguardtype-guardtype-checktyping system

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wookieb-type-check/health.svg)

```
[![Health](https://phpackages.com/badges/wookieb-type-check/health.svg)](https://phpackages.com/packages/wookieb-type-check)
```

###  Alternatives

[phpoption/phpoption

Option Type for PHP

2.7k541.2M159](/packages/phpoption-phpoption)[jetbrains/phpstorm-stubs

PHP runtime &amp; extensions header files for PhpStorm

1.4k27.7M68](/packages/jetbrains-phpstorm-stubs)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49444.8M97](/packages/marc-mabe-php-enum)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1831.1M18](/packages/consistence-consistence)[symfony/type-info

Extracts PHP types information.

19751.9M114](/packages/symfony-type-info)[pinkary-project/type-guard

Type Guard module is part of the Pinkary Project, and allows you to \*\*narrow down the type\*\* of a variable to a more specific type.

198102.4k14](/packages/pinkary-project-type-guard)

PHPackages © 2026

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