Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114067 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60539 invoked from network); 18 Apr 2021 14:25:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Apr 2021 14:25:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3254E1804F3 for ; Sun, 18 Apr 2021 07:27:19 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-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,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 18 Apr 2021 07:27:18 -0700 (PDT) Received: by mail-lj1-f177.google.com with SMTP id a25so23082111ljm.11 for ; Sun, 18 Apr 2021 07:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9qs69rCKjK0dv0wR2z2H0wXBAgUiiSsoHG1aY2dUPCM=; b=ZLUqOYvBEWDS4+P589T2Mskz8CkUpQKtbF9KvaGgPNTv6+DwliIm7LQuJEufh6WLE1 DMBi5VyzGfJ7l31/+9VUkKO2PbMuSX0qeaJkFJ7+3e4M01eBpujE5CxV7oUQLFUz1Meg KLkYp/CiK67QzpYkrAvBQP2SlFBGgV4lbjaVdLXhEeoIQnhL2wxTfeNkNbH3T3bCDhn4 hJEJpmArHxAvf0FOR52y67KmAyoTacGZ3k0r2qmZXPwtte64TRr85hibWKigL7H5ND4m 8iMx80EPzroL0yVS0WahTr7sJbQmcROeyJMsyf3duw8Nb8blttFrji83g7wsarzwHbq7 A9jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9qs69rCKjK0dv0wR2z2H0wXBAgUiiSsoHG1aY2dUPCM=; b=pmtWP1sXYqUSZkXq7vRaXPwRtl0NdPuQ3haffINvc9nAJss1Y5D4eYv8/h27uwvr1J HotQZge+U+GuP664BUQLy3yCUwfFp303/ZM2MM8d/cdZTzoFUShp8L3rEhIUtgUsnZWL 8lbe54v/HZzWDKGBH2X2h2HTILaklumQuc0AYAIr/Q0EZtdHdeMQOnIlTp7qAgBNXVOn +JnyP4sXe6H8KAD3mnXqCvTHGmjhiH3sroE+DglL9ybC8a9zCCJFFnMQAS/wcmhgbS4s HhxE4jc2pID1nQES+d8E9OAlvHH6iSXfsZQCAYziPBB0ME4UMZ2vVolZi6Cw6mDKGK2r yTWw== X-Gm-Message-State: AOAM533UahSz6Mi2Sth0WBoS32Us8L0Lk5kHZaAdevXVzL/ry8jte5jZ +lnyEe7r5UKPKdZ6yNomPu0s/me6wxtpZeEr7uw= X-Google-Smtp-Source: ABdhPJxaj66EBuDBK7PTiMsRuhuwbiAgGPncmqy61D8WZReYHm+a9d10Kh0nV3V4Vpwt7Mr4WOaMVRnDVQ4LDtbPTEw= X-Received: by 2002:a2e:5716:: with SMTP id l22mr8460949ljb.244.1618756036368; Sun, 18 Apr 2021 07:27:16 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 18 Apr 2021 16:27:00 +0200 Message-ID: To: =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000869d1205c0400260" Subject: Re: [PHP-DEV] [RFC] [Draft] Final constants From: nikita.ppv@gmail.com (Nikita Popov) --000000000000869d1205c0400260 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Apr 18, 2021 at 4:20 PM M=C3=A1t=C3=A9 Kocsis wrote: > Hi Internals, > > I've recently realized that class constant values cannot always be truste= d > when late static binding is involved (e.g. static::FOO or $this::FOO), > since they can be freely overridden in child classes. That's why the engi= ne > knows neither the type and the value before run-time. > > Doctrine coding standards has a specific rule which disallows referencing= a > possibly overridden class constant ( > > https://github.com/doctrine/coding-standard/blob/8d75920bb04a9be4c73c2a77= 5ee5766262cf2a0d/lib/Doctrine/ruleset.xml#L123 > ), > but I'm wondering if it would be better to simply make it possible to all= ow > declaring class constants final (thus disallowing overriding) instead? > > In my opinion, final constants would come with two advantages: > - make class constant declarations paranoidly safe > - allow the engine to optimize class constants references in LSB context > > Although I admit that the win is not extra huge, I do think that it would > still be useful to have this feature, especially considering that the > implementation is very straightforward ( > https://github.com/php/php-src/pull/6878). So that's why I'm proposing > this > as an RFC. > > Recently, a similar attempt to make class constant declarations safer was > the Typed Constants RFC (https://externals.io/message/110755#110755), but > unfortunately it has halted since then. I think final and typed constants > would be a nice little addition, and would complement each other well. > > Regards, > M=C3=A1t=C3=A9 > I think if we add final class constants, we should also clean up the current semantics for class constant overriding at the same time. The problem is that interface constants currently cannot be overridden directly (https://3v4l.org/jsDRO), but they can be overridden indirectly ( https://3v4l.org/IkvJe). If we have final class constants, then we should say that class constants are always overridable by default (regardless of whether they are declared in an interface or class), as we now have an explicit way to opt into forbidding the override. Regards, Nikita --000000000000869d1205c0400260--