Value Object

A value object is a design pattern used to represent immutable objects that encapsulate a set of related values or attributes. Unlike entities, which are identified by their identity and can change over time, value objects are defined by their state and remain constant throughout their lifetime.

Value objects are typically used to model concepts that don’t have a distinct identity but are important for the behavior and correctness of the system. For example, a Date value object can represent a specific date, and its attributes may include the year, month, and day. Another example is a Money value object that represents a monetary amount, including attributes such as the currency and the value.

<?php

class person {
     public $name;
     public $lastName;
}

?>

Documentation

See also Writing value objects in PHP, Value objects in PHP, Is it a DTO or a Value Object?, Bring Value to your code, Value Objects in PHP 8: Building a better code, Advanced Value Objects in PHP 8

Related packages : sebastian/type, cuyz/valinor