Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125705 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 423A51A00BD for ; Sat, 28 Sep 2024 17:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1727545971; bh=J/9hPr/uqsxIK0S5k8cdbJkCoHum//Jtigo4Hvd0ZR0=; h=From:Subject:Date:References:To:In-Reply-To:From; b=gMb7ZIcoTj4brLz5tl8uGXNrlqMcEp9q3l273MYcsnIcSi2jVZIuxsXyWZrDhP1h7 pQXDExRxuVk7+dQvFn+Zjk8L3eCJ83x6FZSh8RWeMMkLvynBW5HGU8BnKM23K68yuc td7N6rG/2hkcgVDPSnXJhnshpmhdWnF1KJDC6yQCS6E2FGul7+OJx/hxBOYxp1yV5u XrIuQ0OkSGMBVFLvZGlmRRzNvDKbhbLfWiLNvLAnPr/SnHjGWMg8U2qVRNXEeMkZ2S UYVVhuqcsGnB+euhCPVb7IC+rhwXg6y1gv+HoyRqLQb04XH0sm/+JJJOqnHo9Vw6fm QYGtsfgWSgXeQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A739F18004A for ; Sat, 28 Sep 2024 17:52:50 +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_MISSING,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from nebula.zort.net (nebula.zort.net [96.241.205.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 28 Sep 2024 17:52:49 +0000 (UTC) Received: from smtpclient.apple (pulsar.zort.net [96.241.205.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nebula.zort.net (Postfix) with ESMTPSA id 19BC6200B627A for ; Sat, 28 Sep 2024 13:50:38 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 nebula.zort.net 19BC6200B627A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zort.net; s=zort; t=1727545838; bh=iW0WWt9g1zLYW2QG37FFNc/ObzpkQxnVkW4iPQaWfkA=; h=From:Subject:Date:References:To:In-Reply-To:From; b=gDgkGIRffgE50dG/DIlmAxEybM8Tatwcc+ADE2nDdT+0fkB40MkUpHDfPXsoEieV2 pfJ/FA2nKSvZ29XBP/yf9MI/8tLEsKwdSzwf37g2oyVOzmB/TlkmDTW29w14L34F8A skQYa0RhRROsSfulw5iWfujrQY1j0B7B7wjhdvuU= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.1\)) Subject: Re: [PHP-DEV] Protected destructors Date: Sat, 28 Sep 2024 13:50:27 -0400 References: <0a45288d-8ae1-4b1c-8836-6bdd1cf34eb2@gmx.de> To: php internals In-Reply-To: Message-ID: X-Mailer: Apple Mail (2.3776.700.51.11.1) From: jbafford@zort.net (John Bafford) On Sep 28, 2024, at 13:23, Jonathan Vollebregt wrote: >=20 >> Okay. My point is that you cannot know (unless there are no circular >> dependencies) *when* a destructor is called by the engine; >=20 > The benefit of non-public visibility isn't when it's called, but how = many times it's called. If you can declare your destructor non-public = you can be confident it'll only be called once per instance (By the = engine) >=20 > Or is there a scenario where the engine will call a destructor more = than once on the same instance? >=20 >> Destructors should (IMHO) be public. Not necessarily because they can = be called, but classes with destructors hint at underlying behavior when = destructed. For performance, you might want to defer that by retaining a = reference. If a class has a hidden destructor, you have to go read the = code to find it. >=20 > Wouldn't you have to read the code to see if it had a public = destructor too? I would argue that, semantically, destructors should be *private*. You = should never need to know if a class has a destructor, and you should = never call it manually. The engine should automatically handle calling = parent destructors when necessary. If there really is some logic in the destructor that a user of a class = might legitimately want to use, then that should be exposed in a = separate method (with a more appropriate name, and an implementation = that handles that it might be called more than once) and have the = destructor call that method. -John=