Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112624 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27758 invoked from network); 27 Dec 2020 14:45:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Dec 2020 14:45:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A0F4C1804BE for ; Sun, 27 Dec 2020 06:19:19 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 27 Dec 2020 06:19:18 -0800 (PST) Received: by mail-lf1-f53.google.com with SMTP id o19so18726084lfo.1 for ; Sun, 27 Dec 2020 06:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=SBTwMTVb37hUuceiOW8KwZKGMdaLn+JCC4TFjaatAq8=; b=NI5IaOe6rnBsKpXFkHiFmTzor1FlokSkZrxPHjvi3OMSXWYFyaj23WMQHfuvOXEZri a5OC6YAwlZeCAoHt08Jbh2KdaPHDq01HFNeb1DgLgOGqooMcLDzBQjuj2D0GCwbn347j 7RM/9xOibx3fOmIsE9XNBLy0ONwq02sqHAH3oPjsg4E/zd3j55fqFLq0rlJJmouX8JHj XpCm7HxfSXbOjQtOFuyMh0/1dgInckrAHFNWEu8gCO0GpQo7/y4ZjELxQdTWGK0xNKGv BSzjUyJfkE2BDgbe40y31rGUB7nIzO2LIAad/lMxSYbunPw4+6S9hm+xS93oRXoSsQuJ M2qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=SBTwMTVb37hUuceiOW8KwZKGMdaLn+JCC4TFjaatAq8=; b=fVhQyjzpkLuZ1DokCXiMDTiMo6tKLckbR+Q2+cw6Ty3jQhQ6Pxya9MCjHjSkQepv7G 6pyCBXSYTP+bhYO+XDsGNuc/kHn8DTpDHj2YsbdtLNecOBbohD5C1XRGytxSS7KGlgrL UT+BVpf7wubE7Chu4xXCHLry+PnwOHGqNNnBfJOy0MOO8bwRK4jt80M1ZRxun8IuCSF4 2NBLAnKdxWfad53iA85q6avZQhovSv8UI5eWIJas7RVv7wrnSp+Oh67u/+JYLPrNjLxt nPsM36BYhhi5OMSTCdeYknUBoOx/+ml5lIn6R8oGZ4HrAo69nXbSrQddjePzpTvLIqb1 Y5/A== X-Gm-Message-State: AOAM533Y64KG4T4rC3CL4q9F+KoBuXxXFe5NVpUe8Q+cFY/2uLkwE3GE 48wfbW7CNguHvKQjp/xqTIcBI3UX2kZtwqVRgZBbKkxj+S4= X-Google-Smtp-Source: ABdhPJyJ2pYiYR4DV8D14f9IxoVT5kCyE+9ZIrmN8bJH7plu3+LcpfL5Rs7vdHomDGwhai4lOGUUgCFFtd4/6EY8vIc= X-Received: by 2002:a05:6512:693:: with SMTP id t19mr18695793lfe.22.1609078756933; Sun, 27 Dec 2020 06:19:16 -0800 (PST) MIME-Version: 1.0 Date: Sun, 27 Dec 2020 15:19:05 +0100 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000b9041305b772d777" Subject: [RFC] Property initializer for clone From: kocsismate90@gmail.com (=?UTF-8?B?TcOhdMOpIEtvY3Npcw==?=) --000000000000b9041305b772d777 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Internals, I'd like to propose a new RFC which would make dealing with immutable objects a bit easier and slightly more efficient. The RFC is about adding support for property initializers when using clone. In order to illustrate when this feature would be useful, let's take the following example: class Foo { public $bar; public $baz; public function withProperties($bar, $baz) { $self =3D clone $this; $self->bar =3D $bar; $self->baz =3D $baz; return $self; } } While "with" methods are currently written the above way, my RFC would allow to write this instead: class Foo { public $bar; public $baz; public function withProperties($bar, $baz) { return clone $this with { bar: $bar, baz: $baz, }; } } An initial implementation is available at https://github.com/php/php-src/pull/6538 Initially, I started working on this feature because of the feedback my "Write-once properties" RFC got back then - namely that "write-once" properties didn't work well with cloning -, so I wanted to circumvent this limitation. However, I realized in the meanwhile that "clone with" would be a nice little addition to PHP regardless of "write-once" properties, that's why I'm proposing it separately. Please also note that I don't want to introduce property initializers as a general way to construct objects, so I personally have no plans to extend this construct for the "new" operator. Regards: M=C3=A1t=C3=A9 --000000000000b9041305b772d777--