Simple Data Objects
Lightweight, attribute-driven DTOs for PHP 8.4+.
Works standalone or inside Laravel 10–13. No reflection in production.
composer require std-out/simple-data-objects
Why
| Simple Data Objects | |
|---|---|
| Hot path | Compiled per-class closures — zero reflection, zero dispatch overhead |
| Boilerplate | None — constructor props + attributes |
| Roundtrip |
from(toArray()) always works, mapped keys included |
| Standalone | Validation works without a Laravel app |
| Pipelines | Middleware-style input preprocessing, class or property level |
Performance
Benchmarked against the most popular full-featured data-object library in the PHP/Laravel ecosystem — identical DTO shapes, 20,000 iterations per scenario, PHP 8.4:
| Scenario | Simple Data Objects | Popular alternative | Advantage |
|---|---|---|---|
| Hydration — flat DTO | ~4,500,000 ops/s | ~130,000 ops/s | ~35× faster |
| Hydration — nested DTO | ~2,200,000 ops/s | ~74,000 ops/s | ~30× faster |
| Hydration — collection of 20 | ~270,000 ops/s | ~7,500 ops/s | ~36× faster |
| Serialization — flat DTO | ~7,400,000 ops/s | ~200,000 ops/s | ~37× faster |
| Serialization — nested DTO | ~4,000,000 ops/s | ~117,000 ops/s | ~34× faster |