attributes-php / strictify
Pydantic-inspired PHP library for validating data via type hints at lightning speed
v1.1.0
2026-11-27 17:42 UTC
Requires
- php: ^8.2
Requires (Dev)
- carthage-software/mago: ^1.50.0
- illuminate/translation: ^12.0 || ^13.0
- illuminate/validation: ^12.0 || ^13.0
- pestphp/pest: ^3.0
- phpbench/phpbench: ^1.7
- respect/validation: ^2.5 || ^3.0
- symfony/validator: ^7.4 || ^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Strictify is a PHP library for validating data via type hints. Your model types are the schema: no configuration files, no YAML.
Prerequisites
- PHP 8.2 or later
We aim to support versions that haven't reached their end-of-life.
How it works?
<?php use function Attributes\Strictify\validate; use Attributes\Strictify\BaseModel; class User extends BaseModel { public float|int $age; public ?DateTime $birthday; } $rawData = [ 'age' => 30, 'birthday' => '1994-01-01T09:00:00+00:00', ]; $user = validate($rawData, new User()); var_dump($user->age); // int(30) var_dump($user->birthday); // object(DateTime) { ["date"] => string(26) "1994-01-01 09:00:00.000000", (...) }
Need to call a function?
<?php use function Attributes\Strictify\call; function myFunction(User $user) { var_dump($user->age); // int(30) var_dump($user->birthday); // object(DateTime) { ["date"] => string(26) "1994-01-01 09:00:00.000000", (...) } } call("myFunction", $rawData);
Installation
composer require attributes-php/strictify
For maximum speed, install Strictify Extension instead — the native C extension flavor of the same library. It shares the same API, behavior and documentation, so no code changes are needed:
pie install attributes-php/strictify-ext
Documentation
Full documentation lives at strictify.attributes-php.com:
- Quickstart — first model and first validation in under a minute
- Guides — validating payloads, nested models, aliases, error messages, sensitive data,
call(),toDict() - Reference —
validate(),toDict(),call(),ModelConfigs, constraints, exceptions, API - FAQ and Changelog
- For LLMs and agents: llms.txt indexes every page (each also served as Markdown), and llms-full.txt has the full docs in one file
Strictify Extension was created by André Gil and is open-sourced software licensed under the MIT license.