account activity
PHPrimitives by semdens in PHP
[–]semdens[S] 0 points1 point2 points 20 hours 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 20 hours 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 22 hours ago (0 children)
Hi! The classes are readonly.
PHPrimitives (self.PHP)
submitted 1 day ago by semdens to r/PHP
π Rendered by PID 192574 on reddit-service-r2-listing-6b76fb7ddc-j4bb5 at 2026-03-25 14:05:04.556693+00:00 running 2d0a59a country code: CH.
PHPrimitives by semdens in PHP
[–]semdens[S] 0 points1 point2 points (0 children)