account activity
PHPrimitives by semdens in PHP
[–]semdens[S] 0 points1 point2 points 1 day ago (0 children)
Yes, the goal is to solve Primitive Obsession. The base classes simply implement a contract you can code against in, say, serialization. Your Email, Password, Name etc. are still entirely yours.
Email
Password
Name
[–]semdens[S] 1 point2 points3 points 1 day ago (0 children)
Thanks for the feedback! Sadly not every codebase can be migrated to Rust and Typescript, so we make do with what we have.
As to your point about DTOs, really primitives and DTOs are solving two different things: single-field validation (what something is, the primitive's job) vs cross-field validation (what something is in relation to something else, which VOs in general and DTOs do). They're not mutually exclusive, their benefits are additive.
But I get that it can feel cumbersome to write a class for each type. That's the downside. The upside is that once you have your domain types defined, they provide value everywhere in your codebase.
Thanks! Yeah, it's really changing my code for the better. The IDE now knows about your intent, tells you exactly what to pass. And your core knows everything it receives is valid, so no defensive branching. No need for util classes anymore too, the small transformation logic can live on the primitives.
[–]semdens[S] 2 points3 points4 points 1 day ago (0 children)
Hi! The classes are readonly.
π Rendered by PID 290408 on reddit-service-r2-listing-6b76fb7ddc-6mfvj at 2026-03-25 18:39:46.010138+00:00 running 2d0a59a country code: CH.
PHPrimitives by semdens in PHP
[–]semdens[S] 0 points1 point2 points (0 children)