Sitemap

Member-only story

Avoiding Primitive Obsession in PHP

11 min readDec 1, 2025

--

How Value Objects Help You Write Safer, Clearer, and More Expressive Domain Code

Press enter or click to view image in full size
image from deviq

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, float is 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”.

--

--

Ann R.
Ann R.

Written by Ann R.

Backend | BI | Automation — Growing through every lesson in tech and life. For anything, hit me up at: r.ann98723@gmail.com