Skip to content
Wade Womersley

wade.one

wade womersley – york based software engineer

  • Home
  • 2026
  • May
  • 10
  • PHP 8.5 Clone With Makes Value Objects Less Annoying

PHP 8.5 Clone With Makes Value Objects Less Annoying

Posted on May 10, 2026 By
PHP, Programming

PHP value objects have become much nicer over the last few releases, but cloning them has still been more awkward than it should be. Readonly properties are useful, immutable objects are useful, and withSomething() methods are useful. The annoying part has been writing the same cloning ceremony again and again just to change one property safely.

PHP 8.5’s release announcement calls this “Clone With”, and the clone-with RFC explains the real motivation: making clone work properly with readonly properties and common wither-style patterns. That is exactly the kind of small language feature that matters in domain code, because value objects are only pleasant if they stay lightweight.

I would not use this as an excuse to make everything immutable. PHP applications still need simple mutable objects in plenty of places. But for money values, date ranges, identifiers, request options, API payload objects, and other things where accidental mutation causes pain, clone-with syntax lowers the cost of doing the cleaner thing.

The important caveat is validation. If a value object has invariants, cloning with a changed property should not become a side door around them. That is where PHP’s newer property tooling starts to fit together: readonly, asymmetric visibility, property hooks, and clone-with are more interesting as a set than as isolated features. The direction is good: less boilerplate, more explicit object state.

Share:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit

Related

Comments

comments

Tags: php php-8-5 readonly value-objects

Post navigation

❮ Previous Post: PHP 8.5’s Pipe Operator Is for Readable Code, Not Clever Code
Next Post: PHP 8.5 NoDiscard Is a Small API Safety Feature ❯

You may also like

Programming
Cloudant (IBM) Query – Indexing arrays directly using Erlang
July 6, 2015
PHP
PHP 8.5.4 Released: Upgrade if You’re on 8.5
March 25, 2026
Programming
#leedsphp talk slides uploaded
April 22, 2011
Programming
Why Kotlin Coroutines Are Worth the Learning Curve
April 14, 2026
  • AI
  • artificial intelligence
  • Ego-centric
  • Events
  • Films
  • Food
  • Gaming
  • Gym
  • Hardware
  • Holidays
  • News
  • PHP
  • Programming
  • Random Stuff
  • Reviews
  • Science
  • SEO
  • Software
  • Software Engineer
  • Support
  • Uncategorized
  • Work

Copyright © 2026 wade.one.

Theme: Oceanly News Dark by ScriptsTown