Dev.to
7/12/2026
Compiling PHP DTOs: from reflection to 4.5M hydrations per second
Short summary
A deep technical article on compiling PHP DTOs to eliminate reflection overhead. The Simple Data Objects package generates a specialized closure per data class at first call, turning property hydration into inline array reads with no per-call dispatch. Combined with opcache persistence and PHP 8.4 lazy ghosts, the approach reaches 4.5M hydrations per second.
- •Generates specialized closures per DTO class, replacing interpreted hydration loops with compiled inline reads
- •Reflection and attribute reads happen once per class; generated code is opcache-persisted
- •Plain properties become direct array reads; casted properties delegate to a shared ValueCaster with metadata captured in use
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



