Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127463 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 9320D1A00BC for ; Mon, 26 May 2025 15:10:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748272131; bh=kx2k2EMSJtqbL6HWaV11KJHvdCCGRuiIjPzpkdioOvQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RGzVkYtYPcuteE1uGqofmlr2nvSBYU9LIcjBNZEa9fqNapFfjhqsrBKfujQDX3KJC wIMXnu2/sIjr8OAmP79sAyk6xoGN9WcqDk80L1g3Q8YHWvhK4fwTrkxTysqH970/GY Rpd+fx8pQ0QEnwnRpc22YmuHMRkZDFgbOLcqUkbsTNARYRf8TP8Zvkj7VUiLRbwn71 pU7Jp2pJhs02MNopzcsehiF6yDSc9VZlV8a/Ez6Df94yvJgJ/kGlMCMD1HcWhOK3yo wSHLgk+RgSIUxz1ZFXoNEBHKI6ZehqIx+BprwiuV6muy9VNMYEHXkzi4u0t/D09/dz AvTvmwdq73tug== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 774D31805EF for ; Mon, 26 May 2025 15:08:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 26 May 2025 15:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1748272253; bh=H7fFun2VGDr7JoGDLjs8lOOKpTbieG98JONNyrf3OJw=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=mJnahl3Q0IY9gHmnYqM5xB/EjsvLGu8uttRJ9A7amvrxQPWahJJsd7Ht70lEslR/f cbE7TVIPTW92WJJ3wOTUDS40jeOrXFWEnJocSNIKrmnx39dHyMk0dswXlE0Hw6Kjw8 FGts5pmVI7zxTYtZBUbxy9qK/W/brmSFBZOF5w4c2ygN54c3Z35EBBXNPlHjVNCpyW kQQawKdkyGigbnu0R2mKI1ZZ7gjMn9Ken1xO2ohdYn0e3d9H9/15qG8su5uaOXrEs8 v2o0jQzhSri+LSbsjDp4joCchx9KNwPfqJI2yRRojr4GTrovNuOb0l0OZipHy69dbS 8K/8mbCi6ijWA== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 26 May 2025 17:10:53 +0200 To: Nicolas Grekas Cc: Volker Dusch , php internals Subject: Re: [PHP-DEV] Re: [RFC] Clone with v2 In-Reply-To: References: Message-ID: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Clarifying on the technical questions. Am 2025-05-26 16:37, schrieb Nicolas Grekas: > I think the RFC is missing a few bits to be complete: > > - making "clone" a function means suddenly a "use clone;" or a "\clone" > is > going to be needed to not get a perf hit, isn't it? But since $y = > clone > $x; is still going to be valid, how will this be handled? The RFC could > give some more hints on the topic. The implementation of making clone a function matches that of making `exit()` a function in PHP 8.4 (https://wiki.php.net/rfc/exit-as-function). Specifically, `clone` will remain a keyword and any use of a bare `clone` will compile to a fully-qualified call to the clone function, as if you would have written `\clone()`. For the same reason it will remain impossible to define a `clone()` function within a namespace. It will also be disallowed to use `disable_functions=clone` (the same as with exit and die). That `clone()` will become a function should be considered an implementation detail. You might start seeing a `clone()` frame in your stack traces, within `assert(false && clone($foo))` the `\clone()` call will be fully-qualified in the error message output and error messages might slightly change (e.g. when passing a non-object to clone). Other than that, it should not be noticeable. Perhaps even the ZEND_CLONE opcode will remain when using clone with a single-parameter (this is similarly to the other optimization of “special functions”, such as count() or sprintf()). I have made the following changes to the RFC that should hopefully clarify things: https://wiki.php.net/rfc/clone_with_v2?do=diff&rev2%5B0%5D=1748270099&rev2%5B1%5D=1748272162&difftype=sidebyside > - writing code with a wide range of supported PHP versions means we'll > start using construct such as: > if (PHP_VERSION_ID>=80500) { > $b = 'clone'($a, [...]); // note 'clone' is a string here, so that > the > line is valid syntax on PHP <= 8.4 > else { > // another code path for PHP 8.4 > } > That's of course because "use clone", "\clone" or "clone($foo)" is > invalid > PHP syntax currently. Only `use function clone;` is currently invalid syntax (and it will remain invalid syntax, similarly to `use function exit;`). `clone($a)` currently is a perfectly valid cloning statement (with redundant parentheses) and `\clone($a)` is a valid call to a function called `clone` that does not exist: https://3v4l.org/VB3j1 But as I said above, it is not necessary to change any existing code. The RFC is clear on that: There are no backwards incompatible changes regarding the usage. When finalizing the implementation, I'll make sure to run some benchmarks to determine whether or not keeping the OPcode is worth it for the “non-with” case, or whether making clone a “frameless” function would bring any benefit. But making sure it runs fast is the job of the engine, not the job of the PHP developer and generally speaking performance characteristics can change even without RFCs. > It could make sense to tell about this and show an example like this > one in > the RFC. Given that your question appears to be based on a misunderstanding, I believe adding such an example to the RFC is not useful. > - what if one gives a mangled property in the array? clone($foo, > ["\0Foo\0bar" => 123]) > It could be useful to write something about this case and/or at least > have > a test case that shows how this should behave. As the RFC specifies, clone-with behaves exactly like regular property assignments. This means your example behaves like `$foo->{"\0Foo\0bar"} = 123;` and thus will throw “Error: Cannot access property starting with "\0"”. I have added a test to the implementation [1]. Adding that to the RFC text itself is probably not useful to the average reader, since this is not something they will encounter. Best regards Tim Düsterhus [1] https://github.com/TimWolla/php-src/pull/6/commits/6f55e142e55af013bed0f31d7dc1633ef8201bff