Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126563 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 qa.php.net (Postfix) with ESMTPS id E01811A00BC for ; Tue, 4 Mar 2025 21:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741122694; bh=7Xv9CshagGeLBn/43sMSfpB1uN/XYbz8/qITYcYe9oY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Tq2meyaVylVTSfKX6YW1+YI6KIb1dK371KWg5jK+Z11yi4SGvMxhMYDnyBMt+G9Sz GZQun4H7RpEzcefBxAk9ZzAFZe1E+lAcViJbgh9NTvMstQkpTsf4DVObIIftRWZVB0 o+wtUF++oL857Pf44QAu65xvP80Rh44F+WB35vxSgSbY3LHzj63Bx3tRgdNJBR5nn2 knDbHHnfuFEoOr1FI5iXxoFVUSdRNxuHZWie7hjAYSzvu4ARW/U9gMdIj/ZBb4QHy2 wYjBw/bJ9vGOeWZVHif2xdGJDKZXqkxJmibRvgZoGG5OIGmNaCFA4ReaFdn4EzABX+ OtogUI1DNkQ7g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AFCBD18006D for ; Tue, 4 Mar 2025 21:11:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-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,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No 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 ; Tue, 4 Mar 2025 21:11:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1741122847; bh=Q5e7TAWcKuY10SGmMHnOPCoU5hLSPjSudXmH96LSdAA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=W34VabU7FFxYFPKJ56u+8kGKhuSB891M2ez0wX2AVJQTQWE5RmnlLueB5HX3QKLTu PztP74S502x0P1NdCWLtWJfckg+/kt1Ma3NGUmXYXtwQC1CIxVlo+jPS7fMUWXFv2j zjLEXHc+f2IwohtLHEUQU93K28auTvjvLb1wVaK/rku49rQ4LX8XmvYBxAfI0K0LeP nvrQg4HMz2YPLbsHrE4iDyEB+VwxmYHAzRkiN2/ZbGsf1wHCl2U1FZx/P19NBk6NGk pkkZpogrFJBqYTNz/HEcvT7WoipvXw38TyvPC0H1zGGSpeZ9QVBxe70yzrmVI7V/Pr oCAQb0m0WwKug== Message-ID: <1a980468-c5f3-485b-9e8b-8c97d6ac4802@bastelstu.be> Date: Tue, 4 Mar 2025 22:14:05 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] Re: RFC: Marking return values as important (#[\NoDiscard]) To: "Marc B." , Volker Dusch Cc: php internals References: <55b798d4-dcd7-4d81-852b-b78294cdc39d@email.android.com> Content-Language: en-US In-Reply-To: <55b798d4-dcd7-4d81-852b-b78294cdc39d@email.android.com> 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 Marc On 3/3/25 17:14, Marc B. wrote: > In this thread, I only found the information that currently OPcache does not > discard such unused assignments. It would be good to know if such optimization > could be considered to not end up in a situation that such optimization would be > useful but can't be applied as of this feature. Unless it knows for sure that the function is unable to return an object (this includes arrays, which could contain objects), OPcache is already disallowed to elide the dead store. Otherwise this would result in an observable behavioral change, since destructors are called immediately rather than when the variable goes out of scope / is overwritten. For practically all modern code this means that this optimization only affects internal functions, since OPcache only looks at a single file. Thus it does not know about the return type of userland functions defined in a different file. In fact, if you call `get_defined_vars()` or similar functions the dead store elimination is also disabled, since that would result in an observable behavioral change. Should the `(void)` cast not be accepted, we will only special case the assignment to `$_` to not be elided, even if OPcache knows that the function will never return an object. The behavior for other variables will remain unchanged. Best regards Tim Düsterhus