Download the PHP package selfphp/php-typecheck without Composer
On this page you can find all versions of the php package selfphp/php-typecheck. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download selfphp/php-typecheck
More information about selfphp/php-typecheck
Files in selfphp/php-typecheck
Download selfphp/php-typecheck
More information about selfphp/php-typecheck
Files in selfphp/php-typecheck
Vendor selfphp
Package php-typecheck
Short Description Runtime type validation for arrays and structured data. in PHP
License MIT
Package php-typecheck
Short Description Runtime type validation for arrays and structured data. in PHP
License MIT
Please rate this library. Is it a good library?
Informations about the package php-typecheck
PhpTypeCheck
PhpTypeCheck is a lightweight PHP library for validating runtime types in arrays and nested data structures.
It helps ensure that incoming data (e.g., from APIs, forms, or dynamic sources) matches expected scalar or object types.
๐ Features
- โ Validate array elements against scalar or object types
- ๐ Support for recursive (nested) arrays
- ๐งฉ Validate associative structures with
assertStructure()
- ๐ Optional keys with
key?
syntax - ๐ง Descriptive error messages with full path and actual/expected types
- ๐งพ Soft validation via
checkArrayOfType()
andcheckStructure()
- ๐งช Type inspection via
describeType()
- ๐ค Structured error output with
TypeCheckException::toArray()
- ๐งช Fully tested with PHPUnit
- ๐ฏ Framework-agnostic (works in Symfony, Laravel, Slim, or plain PHP)
๐ฆ Installation
Requirements
- PHP >= 8.1
- Composer
This library uses modern PHP 8.1 features like readonly
properties.
โจ Basic Usage
Validate flat arrays
Validate arrays of objects
Recursive validation
Fails with meaningful error
โ Soft validation (no exceptions)
checkArrayOfType()
checkStructure()
๐งฉ Validate structured arrays
๐ค Structured error reporting
If a TypeCheckException
is thrown, you can convert it to a machine-readable format:
๐งช Describe value types
๐ Roadmap
- [x]
assertStructure(array $data, array $schema)
for complex key/type validation - [x]
checkArrayOfType()
andcheckStructure()
for soft validation - [x] Structured error reporting via
toArray()
- [ ] Type parser support for
array<string, User>
- [ ] Optional integration with static analysis tools (Psalm, PHPStan)
๐ License
MIT ยฉ2025 SELFPHP
All versions of php-typecheck with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.1
The package selfphp/php-typecheck contains the following files
Loading the files please wait ....