Table of Contents
7. Two Common Ways We Use Classes in Modern PHP
As our programs grow, we'll notice that not all classes serve the same purpose.
Some classes represent ideas from our problem space — the real‑world concepts our application cares about.
This “problem space” is called the domain.
- If we're building a store, the domain includes products, prices, orders.
- If we're building a blog, the domain includes posts, comments, authors.
- If we're building a ticket system, the domain includes tickets, users, priorities.
A “domain concept” is simply
one of the above meaningful ideas.
And the important part is that:
- Some domain concepts are small pieces of meaning.
- Others are long‑lived things with identity.
- And both are represented with classes.
For documentation and discussion,
developers name these concepts by their purpose:
1. Value Objects — small pieces of data
These are tiny concepts that don't have identity.
They represent a value, not a “thing”.
Examples:
- Money
- Email
- Coordinates
- Temperature
- Percentage
If the value changes, it becomes a different value.
Value Objects are usually immutable.
2. Entities — objects that outlive their data
These are long‑lived concepts with identity.
They represent “things” that persist even as their data changes.
Examples:
- User
- Order
- BlogPost
- Ticket
If the name or status changes, it's still the same entity.
Identity is what keeps it alive.
Why these two matter
Both Value Objects and Entities are just classes.
Instances of both are just objects.
The difference is why we create them:
- Value Objects → meaning keeps them alive
- Entities → identity keeps them alive
This distinction helps our code read like the domain itself
— clear, expressive, and intentional.
Are there other kinds of classes?
Yes — but they are not domain concepts.
Later, we'll meet:
- Services
- Repositories
- Controllers
- Commands
- Handlers
- DTOs
- Factories
These are architectural roles, not domain ideas.
They belong to later chapters, once the reader has a solid foundation.
For now, the two most important ways we use classes in modern PHP are:
- Value Objects — small, meaningful values
- Entities — long‑lived concepts with identity
Understanding this distinction makes the next pages feel natural instead of mysterious.
It also gives us clarity when inspecting code, reading documentation, and communicating with others about implementations.
Tony de Araujo —New York
