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, ... )}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners