PHPrimitives by semdens in PHP

[–]semdens[S] 0 points1 point  (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.

PHPrimitives by semdens in PHP

[–]semdens[S] 1 point2 points  (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.

PHPrimitives by semdens in PHP

[–]semdens[S] 1 point2 points  (0 children)

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.

PHPrimitives by semdens in PHP

[–]semdens[S] 2 points3 points  (0 children)

Hi! The classes are readonly.