On Wed, Jun 4, 2025, at 17:13, Volker Dusch wrote:
> Hi everyone,
> 
> We just opened the vote for the "Clone with v2" RFC:
> 
> RFC: https://wiki.php.net/rfc/clone_with_v2
> Discussion: https://externals.io/message/127353
> PR: https://github.com/php/php-src/pull/18747
> 
> As with every RFC, a 2/3 majority is required.
> Voting ends 2025-06-18 at 15:30:00 UTC.
> 
> Kind regards,
> Volker
> 
> --
> Volker Dusch
> Head of Engineering
> Tideways GmbH
> Königswinterer Str. 116
> 53227 Bonn
> https://tideways.io/imprint
> 
> Sitz der Gesellschaft: Bonn
> Geschäftsführer: Benjamin Außenhofer (geb. Eberlei)
> Registergericht: Amtsgericht Bonn, HRB 22127

I’m just now getting around to really digging into the RFC, and I’m trying to 
understand what problems it is solving.

"withers" as they’re often called in other languages that use "with()" and this 
seems to implement, are most useful in cases of value/immutable objects. In 
PHP, this usually looks something like this:

readonly class Money {
  private function __clone() {
    throw new LogicException("do not clone");
  }
  public function __construct(public int $pennies) {}
  public function with(int $pennies) { return new self($pennies); }
}

$dollar = new Money(100);
$quarter = $dollar->with(pennies: 25);

This is an overly simple example; where we want to make sure we have a single 
"dollar" that would be equal to another "dollar". This implementation of 
clone() seems like it would be quite useful here, but it appears that setting 
__clone() to private would completely make this new clone() break.

So, it seems like this can only be used for things that can already be cloned? 
Things which are directly trying to block an identical clone, but would 
otherwise be fine with a clone that changes the value (e.g. value objects) 
aren’t allowed to use this new feature?

To me, that feels like an oversight in the design.

— Rob

Reply via email to