DEV Community

Cover image for DTO vs VO in PHP

DTO vs VO in PHP

Maico Orazio on February 10, 2024

Data Transfer Objects (DTOs) and Value Objects (VOs) are particularly useful when working with dynamically typed languages like PHP, where switchin...
Collapse
 
chrisgalliano profile image
Christian Galliano

omg dude why are you checking things like this

match (true) {
      ($this->amount <= 0) => throw new InvalidPriceAmountException('amount is negative'),
      default => true
};
Enter fullscreen mode Exit fullscreen mode

this is crazy 😭 just use if

Collapse
 
mart_attacks profile image
Martin • Edited

The answer is in the article's title image. It's tidier / more concise, when extend by additional conditions.
Stacked if/else clauses are ugly to look at. And though, here, it's only one condition, the author obviously prefers to use one style always. As I would.

Collapse
 
insign profile image
Hélio oliveira

VO example?

Collapse
 
graceman9 profile image
Serhii Klochko
Collapse
 
danp profile image
danp

This is not a VO, at all.

Thread Thread
 
graceman9 profile image
Serhii Klochko

Yes, you are right! But I did some research and I think I finally got the concept of VO. If someone interested I think this is a good explanation:
dev.to/ianrodrigues/writing-value-...