Value objects are a very effective tool to improve the quality of your application, as well as the readability of your code. They're particularly useful when working with dynamically-typed languages like PHP, where the move to using more structured types has been pivotal in improving application quality.
class User { public function __construct( private string $name, private string $email, private string $phone ) {}} $user = new User('Paul', 'Conroy', 'paul@conroyp.com'); In this case, we have type checking on our parameters, but we've also got a bug sneaking in here.
readonly class Salary { public function __construct( private float $amount, private string $currency, private float $bonus ) { }} readonly class Employee { public function __construct( private string $name, private string $email, private Salary $salary) ... } $employee = new Employee('Paul', 'home@work.com', new Salary(24, 'USD', 0)); Maintenance advantages
class EmployeeDTO { public function __construct( private string $name, private string $phone, private string $email, private string $salaryCurrency, private float $salaryAmount, ... )}