Image for post
Image for post

As a fledgling programmer you’re bombarded by commandments telling you what’s considered right programming and wrong programming. These edicts can seem very useful and on the surface seem irrefutable. But if they are applied without deeper thought they can do more harm than good. One of the worst offenders is ‘thy code shalt have abundant comments’. Another questionable one is the DRY principle.

‘DRY’ is an acronym meaning: Don’t Repeat Yourself. It is often interpreted to mean there should be no similar blocks of code in a codebase. …

This article summaries a solution to the problem of calling and listing commands in Symfony Console when at least one of the commands is not instantiable.

The problem

By default, Symfony will instantiate all your application’s commands when initialising. If just one of the commands fails to initialize, the entire application will fail — even when executing a command that works fine.

Ordinarily, this shouldn’t be a problem. After all, classes should be instantiable, shouldn’t they? But, in my work at Funeral Zone, we have a use-case of a console application that sits in multiple microservices. Some of the commands in the application are reliant on environment variables (such as database credentials) that are not necessary for all microservices. …

This article is about convenient and safe mutations of composite value objects that implement the null object pattern.

Here’s an example of a composite value object. It’s a user that has two subtypes: an email address and a name.

final class User
private $emailAddress;
private $name;
public function getEmailAddress(): EmailAddress
return $this->emailAddress;
public function getName(): Name
return $this->name;
public function withName(Name $name): User
$native = $this->toNative();
$native['name'] = $name->toNative();
return self::fromNative($native);

To mutate the name of a User you take an existing object and call the withName method on it. This method returns a new instance of User where all the previous values are the same, but name is now set to the new value. …


Chris Harrison

Software engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store