Skip to content

Strictify

Strictify

Strictify is a Pydantic-inspired PHP extension for validating data via type hints at lightning speed. The validation logic is implemented in C and compiled into the PHP engine, so your model types are the schema: no configuration files, no YAML.

<?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) "1994-01-01 09:00:00.000000" (+00:00)

Requirements

  • PHP 8.2 or later

Installation

pie install attributes-php/strictify

What's next

  • validate() — the full function reference: parameters, return value, validation rules, exceptions, and toDict() serialization.
  • Constraints — the built-in constraint attributes and how to write custom constraints in PHP userland.
  • call() — invoke any callable with hydrated models and injected dependencies.

Running this documentation locally

pip install zensical
zensical serve

The site serves at http://localhost:8000 and reloads as you edit the Markdown under docs/.