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
Using SSL in RestClient
March 4, 2011
Programming
Ask for Android Permissions When the Feature Actually Needs Them
November 7, 2026
PHP
PHP 8.6 clamp Is Tiny but Welcome
August 17, 2026
Programming
Linux RAID, MySQL
September 10, 2009
  • 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

Categories

  • 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

Archives

  • November 2026
  • October 2026
  • August 2026
  • July 2026
  • June 2026
  • May 2026
  • April 2026
  • March 2026
  • August 2023
  • April 2023
  • March 2023
  • April 2016
  • October 2015
  • July 2015
  • June 2015
  • May 2015
  • March 2015
  • February 2015
  • January 2015
  • October 2014
  • December 2013
  • September 2013
  • June 2013
  • October 2012
  • May 2012
  • March 2012
  • February 2012
  • April 2011
  • March 2011
  • October 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009

Copyright © 2026 wade.one.

Theme: Oceanly News Dark by ScriptsTown