thorough-php / type-guard
PHP type validator
Installs: 12
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/thorough-php/type-guard
Requires
- php: >=7.2
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: ^0.10.3
- phpunit/phpunit: ^7.3
This package is not auto-updated.
Last update: 2025-10-14 02:35:50 UTC
README
Features
TypeGuard can validate:
- Scalar types:
string,integer, etc.:
(new TypeGuard('string'))->match('foo'); // => true
- Object types:
ArrayAccess,stdClass, etc.:
(new TypeGuard('stdClass'))->match(new stdClass()); // => true
- Union types:
string|integer:
$guard = new TypeGuard('string|integer'); $guard->match('foo'); // => true $guard->match(1); // => true
- Intersection types:
ArrayAccess&Countable:
(new TypeGuard('ArrayAccess&Countable'))->match(new ArrayIterator()); // => true
- Optional types:
?string:
(new TypeGuard('?string'))->match(null); // => true