Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125702 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 34A801A00BD for ; Sat, 28 Sep 2024 16:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1727542284; bh=9ol8SieRLHBPBfeRRpTcwusuiTS12TFLclbcYVZEMSs=; h=Date:From:To:In-Reply-To:References:Subject:From; b=OETcbXt3eidZNnXVnsYNLWZRyhI+D7QVXzlq2kNEd07b4ePKCAxN1ALBrFF8CS+q/ edr5xPw0RnmcQ1wt/g2SrQnOYtvEYKE61wPQYlJBVQLQMUad2X4dMTKfTndX2to6pw q6zp5HXWoNHxtV5tcrKtFJKSTLzx2vzBhJAS7xx2sOsZIfbh9BFVgk3CkYjum0jxQs 90965GYyUgAZmplw8dv0e85gjVNyE7RQDxe/XRM1ZcojzSjP3BECI9IXol3C7q1LWS Noh6sqKcDUPPe8iJIx3dglGSCaInL7Xn8cIr6LDAtWvJV2e6IMhpeySg9yWWUVn0Kx GIAUr92Rm4nUA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 46980180059 for ; Sat, 28 Sep 2024 16:51:23 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 ; Sat, 28 Sep 2024 16:51:22 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 65A221380224; Sat, 28 Sep 2024 12:49:10 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Sat, 28 Sep 2024 12:49:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1727542150; x=1727628550; bh=XFoXHNZO0L 9vps63D1o7L807t+8fTXZdCVgV4qOQvfM=; b=oZKzl0Gl/qGsWQwo5yhilRksnC uXmpGZc8YRluoWg8yuUNGVq/1DYbj/V2tSKMZJFJ7J8uJ6Bo5XDWifWJinPAhvD1 yGX0o5ooWIpyltWXSM28yuO6l4mKozqCdg88XiDo5eyiQ6g56fRZ/VQm0wLQOb8G vOp77zr4RFSddsFvR2FV7fYtE7JeV4aaYqNdESfF0CNGsJ0D21XZ2U248nzP8NP0 x/047lOmSraLhMD185tzigSZ7QukyeMgGCAeQPfv3xvHJUxWetYYBsx5EI6NwVmw hYFD7U53olUo9XIC5BgwOUqgNq9zhoPxvQ9cI+ZZ1HR64vScvlBG02kahVng== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1727542150; x=1727628550; bh=XFoXHNZO0L9vps63D1o7L807t+8f TXZdCVgV4qOQvfM=; b=FF7E5XYlfntzt/29Dzb+I6YTd8bIIl22U/qHVBdoAKtv FYXKxEb1qDuH/3KE1a5GxeEqiilVgRoxjAj3NdB/1P57rmINnxgKTxNYx3eEP1vC S4jjrb1HIzQC41zA7dUwaM43mG1/l2RT+bAfeBpHsTYYwGnCKrkPknnzp72jC1hW KU/WBGoKe6fFVxbcQe2yBmXmllYhbkAKJz00v62ufTVZBI/MuhShwj0h8euEnHuT dbmJE6f0Pt8CbnIzwBI0ZKAdf+21Pc8UQfSueZc3Bip4RQw44ErX3ylDPOuJRCc3 3ItSl2Fc5eIcnbqlyWccsfJ41D81KmhpLImqT41f7A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduuddgkeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtsegrtderreertdejnecu hfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdrtghoug gvsheqnecuggftrfgrthhtvghrnheptdeujedttefhueelhfdtleeiudetlefftdduleeh ffegtdeihefhleeijefgveegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtghpthht ohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheptghmsggvtghkvghrieelse hgmhigrdguvgdprhgtphhtthhopehjnhhvsehjnhhvshhorhdrnhgvthdprhgtphhtthho pehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id CF630780068; Sat, 28 Sep 2024 12:49:09 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Sat, 28 Sep 2024 18:48:49 +0200 To: "Christoph M. Becker" , "Jonathan Vollebregt" , internals@lists.php.net Message-ID: <5813ec39-2cf9-4529-8069-8842d23fe8b6@app.fastmail.com> In-Reply-To: References: <0a45288d-8ae1-4b1c-8836-6bdd1cf34eb2@gmx.de> Subject: Re: [PHP-DEV] Protected destructors Content-Type: multipart/alternative; boundary=b68211fa5666476f90bf63fafc5a0590 From: rob@bottled.codes ("Rob Landers") --b68211fa5666476f90bf63fafc5a0590 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, Sep 28, 2024, at 16:46, Christoph M. Becker wrote: > On 28.09.2024 at 16:21, Jonathan Vollebregt wrote: >=20 > >> Hmm, I wonder about the use-cases of userland destructors. It seem= s to > >> me they are mostly useful for sanity checks, and maybe to close > >> resources. Are there others? > >> > >> If not, I wouldn't worry much about the visibility of destructors, > >> because resources are scheduled for replacement anyway. > > > > Besides closing resources and killing processes I've seen them store > > data to disk for caching, remove temp files, call callbacks/dispatch > > events, change state on other objects, dump stored errors to error_l= og > > in a loop in an error handler... >=20 > Okay. My point is that you cannot know (unless there are no circular > dependencies) *when* a destructor is called by the engine; it may be > called during some GC run, or during the request shutdown sequence. As > it's now, that happens pretty early during shutdown, but that *might* > change when stream resources are converted to objects. So you cannot = be > absolutely sure that everything works as expected in destructors. This > is a general issue for garbage collected languages; some of these have > no destructors at all, for such reasons. It=E2=80=99s undocumented, AFAIK, but the destructor behavior is pretty = dependable atm. For example, local variables are almost always destructe= d at the end of the current (function) scope. I am not sure what streams= have to do with GC, but I can=E2=80=99t see how streams would change th= is behavior. > > It looks like there's quite a lot of use-cases for them (Which can go > > wrong if called twice) that don't necessarily require resources to be > > involved >=20 > Like I said, I wouldn't be particularly worried about clients calling a > destructor manually (that's a bit different for the engine, since > segfaultish conditions should be avoided). >=20 > But I don't have a strong opinion about the visibility of destructors > anyway. I'm fine with allowing protected constructors. >=20 > Christoph >=20 Destructors should (IMHO) be public. Not necessarily because they can be= called, but classes with destructors hint at underlying behavior when d= estructed. 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 c= ode to find it. That=E2=80=99s my 2=C2=A2 =E2=80=94 Rob --b68211fa5666476f90bf63fafc5a0590 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Sat, Sep 28,= 2024, at 16:46, Christoph M. Becker wrote:
On 28.09.2024 at 16:21, Jonathan Volleb= regt wrote:

>> Hmm, I wonder about th= e use-cases of userland destructors.  It seems to
>= ;> me they are mostly useful for sanity checks, and maybe to close
>> resources.  Are there others?
&g= t;>
>> If not, I wouldn't worry much about the vi= sibility of destructors,
>> because resources are sc= heduled for replacement anyway.
>
> Be= sides closing resources and killing processes I've seen them store
> data to disk for caching, remove temp files, call callback= s/dispatch
> events, change state on other objects, dum= p stored errors to error_log
> in a loop in an error ha= ndler...

Okay.  My point is that you c= annot know (unless there are no circular
dependencies) *wh= en* a destructor is called by the engine; it may be
called= during some GC run, or during the request shutdown sequence.  As
it's now, that happens pretty early during shutdown, but th= at *might*
change when stream resources are converted to o= bjects.  So you cannot be
absolutely sure that everyt= hing works as expected in destructors.  This
is a gen= eral issue for garbage collected languages; some of these have
=
no destructors at all, for such reasons.

It=E2=80=99s undocumented, AFAIK, but the destructor beh= avior is pretty dependable atm. For example, local variables are almost = always destructed at the end of the current (function) scope. I am not s= ure what streams have to do with GC, but I can=E2=80=99t see how streams= would change this behavior.

> It looks like there's quite a lot = of use-cases for them (Which can go
> wrong if called t= wice) that don't necessarily require resources to be
> = involved

Like I said, I wouldn't be particu= larly worried about clients calling a
destructor manually = (that's a bit different for the engine, since
segfaultish = conditions should be avoided).

But I don't = have a strong opinion about the visibility of destructors
= anyway.  I'm fine with allowing protected constructors.

Christoph

Destructors should (IMHO) be public. Not necessarily becaus= e they can be called, but classes with destructors hint at underlying be= havior 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.

That=E2=80=99s= my 2=C2=A2

=E2=80=94 Rob
--b68211fa5666476f90bf63fafc5a0590--