Strictify Extension is a Pydantic-inspired PHP library for validating data via type hints at lightning speed ⚡️ It shares its API, behavior and documentation with strictify, the pure-PHP Composer flavor of the same library: same models, same functions — the extension just runs them at native speed.
- PHP 8.3 or later
We aim to support versions that haven't reached their end-of-life.
<?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", (...) }<?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);pie install attributes-php/strictify-extFor the widest compatibility — including shared hosting and managed platforms where PHP extensions cannot be installed — use the pure-PHP flavor instead, which requires no code changes:
composer require attributes-php/strictifyFull 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 - Benchmarks, 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.
