Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120134 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38111 invoked from network); 26 Apr 2023 05:06:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Apr 2023 05:06:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CBA35180209 for ; Tue, 25 Apr 2023 22:06:14 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, 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-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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, 25 Apr 2023 22:06:14 -0700 (PDT) Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-63b73203e0aso40391972b3a.1 for ; Tue, 25 Apr 2023 22:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682485573; x=1685077573; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rQRFuOX2qQTgV/nBB+YZ3cSwoKHNvSNdgSlIAsYA2XA=; b=oZUh7o7+yKZPwL6+ghvStmOllWbIXBv5yHDyY/MMpPRcii74Ij9hhjtgAFqtnyQkCJ BUqpgRIqBmFEURn/22UXgWFBtg5X2HWkmLqdpWKsRi7mTLRMVQKjQwhxz2xcvMMogMTU 3be5Sc4nG9tGyFE4UsKndqybfJZLZ+A5NOiCtLUgf/ufBDMj4l1LK022oph1OgW+xNwS seTX4tN6c8UiRZsKAidv3SEUs0JVMwfKvCKYRcDU2yq7qrouqa3vV1Gn/IQuFEkccM2j qSnrk78eYA3cr4jmiI0N3r+CTtJQcyPAQpYu31P+mGbyHq6g8r08AQYdtsqP5L1IjhTh /QZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682485573; x=1685077573; h=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=rQRFuOX2qQTgV/nBB+YZ3cSwoKHNvSNdgSlIAsYA2XA=; b=B5WrUFYqcdY77ILd00FbKmJwfpuTDQrf0/SVVIzs+UiHhiqBwwTJ08FwwcylKSTsy5 GFZfyy7yioGOPOPM2o2Qi0yC9mPEZGGvX9P0EYMW1hKrR1xxF0vwAX55r6miRt594ELQ 8WRbqXwEufLb9vbCdS5KLXx/ZU7QWRbmgtEuUgpkKNIxAxaDxKUMemgWYVjctkTJgwFo mg4X8iRaG+ZZFsofEP3k9LhG9BJrvVGpQ0U2Wgz5RxSRM0KBIS6i6Of0s8Qa7+nhYOTb 5Br2joONVYbivqV+E81X2dZEd5XfBfBzZPddO7ClewzcWifTth0NbnzWtipBkhlAol7d N/tQ== X-Gm-Message-State: AC+VfDwjUZBdI3VmqxumMd06wsbc7u8CAVqeAwsN0Wy221luYabqpE2Z s8ZdWMvN+2me98i8WTsWS+jQP0/wYNbo4yk/vusDHAw6SwWBHQ== X-Google-Smtp-Source: ACHHUZ7tTvXTNMxwwi8jpgt8BrrfR80WqaYd09Vsa1/0F6STraLfq+wuZHN0QSeaRqGFKVIRPpEXto1kDvIFXX18cQ4= X-Received: by 2002:a17:90b:1a81:b0:247:78c0:125e with SMTP id ng1-20020a17090b1a8100b0024778c0125emr1481891pjb.15.1682485573381; Tue, 25 Apr 2023 22:06:13 -0700 (PDT) MIME-Version: 1.0 References: <799ae864-6e25-4196-a5ce-0d74600a8378@app.fastmail.com> In-Reply-To: <799ae864-6e25-4196-a5ce-0d74600a8378@app.fastmail.com> Date: Wed, 26 Apr 2023 08:05:57 +0300 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000f0f43705fa3632e9" Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000f0f43705fa3632e9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 26, 2023 at 3:25=E2=80=AFAM Larry Garfield wrote: > On Tue, Apr 25, 2023, at 11:23 AM, Nicolas Grekas wrote: > > > What about using a real closure to define the scope we need for cloning= ? > > That closure would take the cloned instance as argument to allow > > manipulating it at will. > > I believe someone mentioned that one previously in the thread. Yes, Nicolas mentioned me. I wanted to get back myself to discussing this topic more as well and find a better solution but didn't get yet time for it. > The problem is that the closure would run in the scope of the object, > not the scope of the caller. That means if called outside the object, it > would allow modifying private or protected properties. The itemized list > of values (whether an array or named-args style) would allow the engine t= o > enforce access restrictions, which is a desireable feature. > As far as I can see, Nicolas was able to find a solution to this problem and so far I like it: The closure is running in the current scope where it is defined and not in the scope of the cloned object. The cloned object is passed as the single parameter to the closure. The suggested clone signature for a class T would be: - clone(T $object, callable(T $clone)): T; // calling clone as a function - clone T $object with callable(T $clone): T; // calling clone as a language construct Alternatively, we can have also: - clone T, callable(T $clone); // without "with" keyword And improve it to allow even multiple closures to be executed: - clone(T $object, ...callable(T $clone)): T; - clone T $object, ...callable(T $clone): T; IMHO, I think we should support both syntaxes. The main reason I wanted to get back to this proposal is because > 90% of a developer's job is to read code and the most trouble is following state modifications of a variable. When that variable to be investigated is a property, so far it was simple to look for "->propertyName =3D ". Editors would easily and clearly highlight all the write access statements or lines (Alt+F7 in PhpStorm). I can't figure out what would be highlighted in the non-closure syntax, especially the one with an array. Thanks, Alex --000000000000f0f43705fa3632e9--