Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125696 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 9ADA91A00BD for ; Fri, 27 Sep 2024 12:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1727440495; bh=kQBApsWyizX0wxYTGbzNHgSIXV39EstYSKrrTXhpoIw=; h=Date:From:Subject:To:From; b=RQqRBjggl25mo7KeTh1UZtNbssMlPjThNW7MVpzGaKx9WDliz+m1Ah4sFkZ9WSLkV AZYblYZReFbEEVipsSAxR+bsXDMQx+FJ0xCJgYxiKMaRVfwobvrFuRYlad/H7h8E/C ts9VZg9YmtqCy1Kc05P/bq3FHLFSTtWyQ/4tvHuCqoPUQSOULJ0IijvvV4XT9hYz+L RQjqDAV4m1XKJ1+8Qe31etcQBeiOFsxP2OvzR+BCRdh51PuxGCtHU/m/hOv3OWnCCA nS2M+rOX7QAAAEl0faMzWhafB0Vr5XZ2p6kshQ6AYLSsAP5gj+A0ef0VELueeivHzO j0ooDVmyefYgg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 772FF180068 for ; Fri, 27 Sep 2024 12:34:53 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from filter101.mijn.host (filter101.mijn.host [5.254.117.212]) (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 ; Fri, 27 Sep 2024 12:34:52 +0000 (UTC) Received: from h26.mijn.host ([2a03:5180:7:2:f264:726d:beae:1]) by filter101.mijn.host with esmtps (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1suA9H-008Nai-52 for internals@lists.php.net; Fri, 27 Sep 2024 08:32:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=jnvsor.net; s=x; h=Content-Transfer-Encoding:Content-Type:To:Subject:From:MIME-Version: Date:Message-ID:Sender:Reply-To:Cc:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=xvKm9CUMVEqnKwUh6llNtQYHda79YpTp3loIwjUYHOM=; b=K qUzF+pCEgqXeyYIWWMzIn+PDzS6lOqAqPNDgea1nrdQwljV28aOXiZsPRMppG8AzyOoxwP1rVEUd7 rIjroKIu3PeNAAl6iacMXYog2bS91kVt2nm8z/gdhhJ0tFHV5OA6jTfcI7GXKgweY3yqB94zz0KPl LYtc+24MA0X1idB+hlKgltBrvPn6nyN79K+ZXfta7slxQ7CW//dfbqQSzFxKoJEU7YE17t/ncBcxa Ee5a5Bc5bJErWkELUFLZBKsXBtV3CJzfcZrj46o+X74YhsO4Q3ZB5VSnPA33RFCefykUzP8MBIBp0 DCRT8yrbcPgDSwSKM4mpMU8mADidqJFcQ==; Received: from 2001-1c00-2a11-3600-106c-2d52-b102-54b2.cable.dynamic.v6.ziggo.nl ([2001:1c00:2a11:3600:106c:2d52:b102:54b2]) by h26.mijn.host with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1su8H8-00000009OSM-2Oc2 for internals@lists.php.net; Fri, 27 Sep 2024 14:32:39 +0200 Message-ID: Date: Fri, 27 Sep 2024 14:32:38 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US Subject: [PHP-DEV] Protected destructors To: internals@lists.php.net Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AuthUser: jnv@jnvsor.net X-Originating-IP: 2a03:5180:7:2:f264:726d:beae:1 X-mijn.host-Spamfilter-Domain: mijn.host X-mijn.host-Spamfilter-Username: 2a03:5180:7:2:f264:726d:beae:1/112 Authentication-Results: mijn.host; auth=pass smtp.auth=2a03:5180:7:2:f264:726d:beae:1/112@mijn.host X-mijn.host-Spamfilter-Outgoing-Class: unsure X-mijn.host-Spamfilter-Outgoing-Evidence: Combined (0.36) X-Recommended-Action: accept X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT++QPVl2nGUYIhCbzVF1Ni2PUtbdvnXkggZ 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5ysVpdc69k5cRExqclQnUjJ0xCugIxICoR4SK4EpYmU4+fH zJ6mVE7ewsipSVIfs4agjHXAXUQgj0nNzU4vM5HbABHVTw1lV42ob3hDgXVUNd9a53XVj4zauHkA 5dPfA2liT1v1qMyQrE//74nL7QExJtdY++svJnY40bnF5nHf8sgP0ewai7osuSxLicS7Z0xd1FgH UTYLOfKNI261jSzBP06AR5g2UA3HqsYlcMd+kd8cjIN3reG9z0FKKQ5m2Qq9zg2TxZPXvudmzwrq BcyfgLO7MZgrpG1FM/jdN8dXf46L6ePdPD8U//CeN+hxbwqoeH3YteOlbHKoDX2BUSfUD2RymD7B wDP+wOngSNcF6ltNgJPPFtzwBzYhvSy5LLbr4xH02iXtFm4w0sCOFbA4fwJOVDCkeSWm5+LqlnjK VX1jFBsgAJ5nbU3C3O/JxYrrYyo8MepuN71J+6qp+twEqp3Ow04hhQJdvb/qAqQPjbNud3PgzKGZ 88iododq/YfVWMlHoWh7YJ70YBk8N5yx6J1fhOzjF0b4LXcjJZ5lomQAQ3iIUpo+uYA8qk3x8ifc BVxRSulCmKGqdC6CZAeQgneYl2CbmQ1c/RYOiDQqnn0oJG9s9jUP25jfq6Ek37WzgWTtGs5KkmJl /obSTS4KZeDIMyi7MLNx5uDctxuJGvQNs8moF0uwcZxVk09AbB730LCTI1bmgn6vkthdwyTiERWe KKG4PAQYNyavp7c49C4od+2UnnEoe67Ur5b8AGQOg3+KKE4orq+HIjrJlb+wwsQ3kaSJnUT6Tnk9 T53aq4jKFojrvUjjKLsywQkk4epFufiSEO0kX4EWsLQt4F9LZQ3W/hKHV3eTrro6IT8uA8gPyiUm KhXR7tc+p12lC/AlCkSujm58a/xB+XC1kCc6Nk02HBbuEgIBsry+WRySKt40eTXlWiUAYdLmsJdA oPIV4U9dEEkpMT0JEU7WaqdTlh5BrxVREcTzf8/gaNTwJDUmEd/Dw3bSBb7ao08FyxsZHnyEwCWd lQd5X2Hzj3/O X-Report-Abuse-To: spam@filter101.mijn.host From: jnv@jnvsor.net (Jonathan Vollebregt) Hello all, On github I reported a bug causing errors when objects go out of scope with a protected/private destructor: https://github.com/php/php-src/issues/16077 Example code: https://3v4l.org/bKijA The magic methods documentation says: > All magic methods, with the exception of __construct(), __destruct(), and __clone(), must be declared as public And true to its word __destruct can be declared protected/private without a warning, unlike other magic methods. Other magic methods however still work even if they're declared private: https://3v4l.org/iCRSe This lead to discussion around whether the engine should be fixed to always successfully call __destruct or __destruct should warn when not public like other magic methods, or contrarily warn when public, or whether there should be special logic stopping manual calls to __construct/__destruct to prevent double initialization as well... But focusing on this specific issue I don't think these BC breaks are even warranted. Since it doesn't work now making it work wouldn't be a BC break unless you were relying on destructor call error handlers as some kind of cursed event dispatcher. A github search for "private function __destruct" found a whopping 298 hits. 296 for "protected function __destruct" The biggest implementation problem I can think of is what to do about class hierarchies. If you require all destructors to be protected (or public) that puts the onus on the programmer to ensure the parent destructor is called, but private destructors would be a headache. It seems the protected but not private destructors idea was already implemented for PHP 7 (https://3v4l.org/6DFGp) but fell victim to a regression in 7.3.15/7.4.3 and no-one noticed because it was never added to the changelog in the first place. Long story short I'd like to suggest: 1. Allow the engine to call protected destructors (again) 2. Warning when declaring a private destructor as with other magic methods 3. Documentation update to confirm private destructors aren't allowed Does this sound good? - Jonathan