Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120066 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33031 invoked from network); 18 Apr 2023 09:40:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Apr 2023 09:40:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2BBAE1804C6 for ; Tue, 18 Apr 2023 02:40:16 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 18 Apr 2023 02:40:15 -0700 (PDT) Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-552ae3e2cbeso77839457b3.13 for ; Tue, 18 Apr 2023 02:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20221208.gappssmtp.com; s=20221208; t=1681810815; x=1684402815; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aEsai6YwDZXnJ/+tnI3zsPEH/eerzxnPPb5iQjbtuHI=; b=eAY9t3OvC28/IO1ud1mNwokCsPIbwhsxezJDQeg/NWhMQPN3an+dMNUPrlQ22TiM8I fhsMTqIJaV0aSYjD3yvoYAV74U/jFYb7TyesoBR6N5q+u6MwvQbaesug7Ltdd7OxaRFC o8UqJ6MngqcS8gDkQ66ijk6R4KaASMzLKTElc1vaA++Cq1Knz0M/acbcBaUec3X4Lo3F O+CBKs61EWDyQ03FfAb1JEix8sz/2pr3oaWN2cOD8N1fScg4HP/knMj7EOlMgBEjLMb2 ZkqTydnU6UJXe6BtdnqmFQCqmWEaf9gfeujon/erMhIn2RqM9YIaCYb3hpKRacXGTYdJ Dd4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681810815; x=1684402815; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aEsai6YwDZXnJ/+tnI3zsPEH/eerzxnPPb5iQjbtuHI=; b=Ct+4f6Mps4gebpSBP1gDq7GKESDEl+A5SZ8aCMF7bCsIbmuuT0r/2rZ5n+YpZ+un0m tBV74ZqOcjKz2HQBPXHizbx/1BzqfhTPJ1AKmxK0Vlp2caLIv09pbBOUd+h/OXtjct3I R64PK9l1gsDR2XdoUiszAItiHfp2GtfgrWMT6helq7m+fKYQM0C6ycaHUwTxrOzyaylb svFAPJsEuL+R4lqHpaCQOllsEyDUB1rbjXsNiz+UeTz093NW9NeWxagQVjGiHe2sg943 biU4u83UD3RIvUcRrEWpTuXXeiykRBybt7WCVNSKq/HJS4lITdhWkcnIHdir9gAmdpFa Ob3A== X-Gm-Message-State: AAQBX9eE7kfn+hSkYqWeoZjcE5HI59XNdGWwfk3L4ETJt93MM9pOt0OK 454/OyfWh7M7sKnUGmrAdtj0eKO1IMUgAGMohN+4+NhepRo6qV8BZ/Q= X-Google-Smtp-Source: AKy350aNyZzOX5XCMGbNFN7ZpZRl8X8Aei2tYD/B0QSuedWnJ5Tz6yYRmcSGXyIHItK+ePzpOK/XrL33QJWujWDKOwc= X-Received: by 2002:a81:83ce:0:b0:545:33f9:3402 with SMTP id t197-20020a8183ce000000b0054533f93402mr20959369ywf.12.1681810815139; Tue, 18 Apr 2023 02:40:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 18 Apr 2023 11:40:04 +0200 Message-ID: To: =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= Cc: PHP Internals List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: andreas@dqxtech.net (Andreas Hennings) > The biggest advantage of Nicolas' proposal over =E2=80=9Cclone with=E2=80= =9D is that it could be made part of the interface contract whether a metho= d modifies the object state. So the PSR-7 ResponseInterface could look like= the following: > [..] > public clone function withStatus($code, $reasonPhrase =3D ''); If this is the main argument, I think I would prefer a more general "readonly" modifier on methods. public readonly function withStatus($code, $reasonPhrase =3D ''): static; > One cannot control whether $this should really be cloned: e.g. if a prope= rty should only be modified based on certain conditions (e.g. validation), = the object would potentially be cloned in vain, resulting in a performance = loss. Exactly. I would say "conditionally clone", e.g. only clone if there is a change, or if we don't already have a cached instance with this value. I think the "clone with" is much more flexible because we can call this anywhere, not just in a dedicated method. This said, I do agree with some of the benefits of the "Alternative" propos= al. -- Andreas On Mon, 17 Apr 2023 at 08:32, M=C3=A1t=C3=A9 Kocsis wrote: > > Hi Everyone, > > Quite some time after mentioning the "clone with" construct the first tim= e > (at the end of the > https://wiki.php.net/rfc/write_once_properties#run-time_behaviour section= ), > finally I managed to create a working implementation for this feature whi= ch > would make it possible to properly modify readonly properties > while simplifying how we write "wither" methods: > https://wiki.php.net/rfc/clone_with > > Regards, > M=C3=A1t=C3=A9 Kocsis