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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners