Member-only story
Avoiding Primitive Obsession in PHP
How Value Objects Help You Write Safer, Clearer, and More Expressive Domain Code
Keywords: php, primitive obsession, value object, domain-driven design, clean code, refactoring, php 8, types, money object, email value object, php arrays, laravel, symfony
1. “Everything Is a String”: The Hidden Smell in PHP Codebases
PHP makes it incredibly easy to start shipping features.
- Need an email? Just use a
string. - Need a price? Eh,
floatis fine. - Need some user data? Just throw stuff in an
array.
It feels fast — until it doesn’t.
You start seeing functions like this:
function registerUser(
string $email,
string $password,
string $firstName,
string $lastName,
string $countryCode
) {
// ...
}Or service methods like:
public function createDiscount(
string $code,
float $amount,
string $currency,
string $type,
int $expiresAtTimestamp
): void {
// ...
}Everything is primitives: string, int, float, array.
Your domain concepts accidentally become “just data”.





