Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125709 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 CB6271A00BD for ; Tue, 1 Oct 2024 11:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1727783936; bh=WjocNP4zn1jfH3KEKXD9RLy2jR6VeI3yFImdHCU7oCY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Q6aL9EhA+Q8+0pbduh7rxtQIRFhncZzQfT00CZL5TblvajGpQ7YTPbbb4aq1s28/e cstz8pKiNwOdhCu0gMX0t7kteSRvM7CkNxm0519WRPEKLWoYrrYOXiTNPo4Bnswbde rfa5OweWrrfY7ejgLF9tdkqOVdQ/N1DFQv5mWuqKlXlJ069fqVz9f6MqlYCRFx5Qod HT1koxUeHYcUnIJaaR5vKfpbgjxKbvgT80jMu77Hucwh22zTMk6raPjA2n3GByi7RD CLIVLKSjzFGz2rkXoDfdgiqUUFLxVWhVSIgz14Z8RBypDQTGEC3QOPrxD3G8CTndCs WHLoWOo74qB9w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8750E180032 for ; Tue, 1 Oct 2024 11:58:55 +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,FREEMAIL_FROM, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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, 1 Oct 2024 11:58:52 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-53992157528so2628387e87.2 for ; Tue, 01 Oct 2024 04:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727783798; x=1728388598; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=WjocNP4zn1jfH3KEKXD9RLy2jR6VeI3yFImdHCU7oCY=; b=KKh7uNdz+4OyQzn1kaYd54kd8pbNI6h4EbdO7ZGb6GqrGpbfhvIDt1Gjq2z9og8+eg h9vzyyC0FXBhj/UkfCb/UyrS4UHaAgmOtsq/e4wTTO9Xu4FYUgnhBQIlDbGE4DB5EbXJ datoYz7ciIAmQN1U71YibdUrnC/KBujnc5Op5/S6O6qA93G5/uJoo/AqsZt2wC7B3fez HMCub2PlDo5spCIZBCUOW4PZhzh2MfJ3YhfHShMp3903KggxlXDh22XF17vmnv/nN/x1 947fkG26jmqaujYFTrzQ+yaB4uyT/WfJwbOhIoDFg/FwOGwItUgB1IFi4b5OPrdRgak8 +lGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727783798; x=1728388598; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WjocNP4zn1jfH3KEKXD9RLy2jR6VeI3yFImdHCU7oCY=; b=kVyCI4iMB+Jsat/5ggZcGobfy1BZZ9UaIZ6pAG1y7J2BrGqWCLrj1HjseVN9f5lvmQ xAEIu6JmlJskpVEMqOnztzBQHbpDLWl7shgLgqpwdwc0hun2WrxhtY0oPBrEtmpTW0Kl Pef21M1xcUgpC7bHfaUgr2itb9hnVGUX1yj+INZaGVKOo00UiaF7EeJA7aeeqF2U6Tla PpruR61Xi1mNB2HFcwu+ZpmBIPphLHSjLUrDEc2MjwL33HHHQErjYLw3piKJZKsnH+Ru E5vPgMuWK8l4KOhxM7dkXvEZ26p9daUBUik88dA+j6QmXiDuxT07Dyr9Qzt4s7wRGr3p fOYQ== X-Gm-Message-State: AOJu0Yzl8Lw09Ju783Ha5JfFWVAtk6T0dnTc45n05Y50NJThWunZHhWC DmO1tJ0V1F+OhItDahUeoeKE3vPepIMqv7UdxcNKijuSx+fVJ339E8z8XEvaX28KvwhQ7JRgYeT a2nqNo2Ln23NuJx8habHKg7kLPpY= X-Google-Smtp-Source: AGHT+IFmYpALti5un6blxXTfx8hP9y+9hQmZgRIDB0TO6GAJoZfDv4Yq4XbZ//tZlKak3tYA772wpZ+dFrfASBLiVic= X-Received: by 2002:a05:6512:130b:b0:530:b76c:65df with SMTP id 2adb3069b0e04-5389fc477d0mr8159766e87.35.1727783797487; Tue, 01 Oct 2024 04:56:37 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 1 Oct 2024 13:56:26 +0200 Message-ID: Subject: Re: [PHP-DEV] Protected destructors To: Jonathan Vollebregt Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: arnaud.lb@gmail.com (Arnaud Le Blanc) Hi Jonathan, > 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. Apparently the engine can successfully call non-public destructors when in the right scope: https://3v4l.org/FEV2fT. This is intentional behavior, as we have explicit visibility checks in the code that calls destructors, and tests for this. This was implemented in the 5.0 development period at the same time as other work on magic method visibility, so my interpretation is that it was likely done purely for consistency. What changed in 7.3.15 is that local variables are now destroyed _after_ popping the current stack frame, which affects the scope in which the object is destroyed in your snippet. This is similar to __construct() and __clone() (whose visibility is used to restrict who can perform the related operation), except that the visibility of __destruct() doesn't really prevent the operation from being performed: the object is still freed after the engine failed to call the destructor. I'm not aware of use-cases for this. Also it would be unreliable as the timing of destructor calls is not always obvious or predictable. Although the current behavior doesn't seem useful, the proposed changes would only address the problem for destructors: We can not apply the same trick to __construct() and __clone(). Best Regards, Arnaud