Steve Grunwell

Open-source contributor, speaker, and electronics tinkerer

Tag: Value Objects

Cloud Gate (a.k.a. "The Bean"), surrounded by tourists in Chicago, IL.

Value Objects, Code Review @ PHP[Tek] 2025

This spring, I’ll be returning to Chicago for another installment of PHP[Tek], where I’ll be giving two talks to help make you into a stronger developer:

Best of all, I’ve been given a discount code to share with y’all, which will save you 10% off the ticket price!

Continue reading→

A dimly-lit, empty factory building

Factory Methods for Hydrating Objects from JSON

If you’ve worked in a lot of codebases, this scenario will be familiar: somewhere in the app, we’re JSON-decoding a string, then using that to pass arguments to a method (such as a constructor). It may look something like this:

$json = '{"first": "Steve", "last": "Grunwell"}';
$data = json_decode($json);

$person = new Person($data->first, $data->last);

I’d like to humbly ask that you stop doing this. Instead, this post is going to show you how to accomplish the same result with a static, factory method and explain why the latter approach will save you all sorts of headaches.

Continue reading→

Taco, a black cat, peeking out of a white drawer

The Beauty of PHP Value Objects

At last year’s php[tek], one of my biggest “holy cow, why haven’t I been doing this?!” moments came from my friend Andrew Cassell when he explained PHP Value Objects in the context of Domain-Driven Design.

Put simply, a Value Object is an immutable object that encapsulates some data and will always be in a valid state.

Continue reading→

Be excellent to each other.