Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114066 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58951 invoked from network); 18 Apr 2021 14:18:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Apr 2021 14:18:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7FEB01804DB for ; Sun, 18 Apr 2021 07:20:11 -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=-0.4 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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:20:11 -0700 (PDT) Received: by mail-pg1-f170.google.com with SMTP id m12so1718700pgr.9 for ; Sun, 18 Apr 2021 07:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=MvuT9gyreSBHxpsAtLv7KkKVnZV+ogWcsE3ZievPFqs=; b=VgCyJcrgAJRTBIFOCaHbo1bYF75U1QH6YDdhmQLKjD0H2Yd604LaAd3EVXocRmfbyC zUDWcShIqSZdPGemi1xt5fUoA0T7IZYOn7OsSFFdDaMAmarJ71Gd0SlKGkM23iKPU2SO 78xyz9DdtamnCZnteanmuUTVrl2R2FPCzSNWa0xIeKiPLMtsT021CJa0HeigYDQoIMiu ahw+nvBoICKTtJnr1oZJj2LUObQnZfz1hr7IQEh/3d1oaL31Z/tnhS3yc1p3O00IW0az W8wJxrZ/U7kYaN0WicrBJcKWkjZJa1G8otINm6EPBtDfKtSH6xSEE0V14FWTIq5G55IL wLOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=MvuT9gyreSBHxpsAtLv7KkKVnZV+ogWcsE3ZievPFqs=; b=ZdFoATKq6YQtIkEKYt+/IaN0zVjCFsoAGA5wod0h5qWjyQ83DlP92F9NNBP5U4R4vh QaFav2n/mKH3erJ6ZbP21uwtqHS7mXrBZwTo46pOrdVpjsBveTPnzZk6Qv09jW7w7IsS 139yV/IQAZ0EK0jbOy+zZBS5Hb/fuoA9n3pPbcLwEWM8GQrogN2B9L58yC47iu/Fh8D0 qC2V7g+4LKNXBWDtZ/3pzD5XbsbDkEqSlsjFkAN9i7l6PNNLV53EWipTCZHaSyDFt/9z Pa/2mmSB/Sy8wtoQxBYew/DEV2mhuRl1TO8FRtibH6jehwlnpvpfUTbNtQAF5DfwH84J LBUg== X-Gm-Message-State: AOAM533TUQ8ul8fHLN8xVoHSOMJO0Dml7qQno8Dy5YA0WJpj9c+kmSIC 9Uup9QKlPGhLnrvj5QaZTtAVCdX/SPsRduevTxLZcrZAUO0= X-Google-Smtp-Source: ABdhPJzWDN/0WOGMGAjf6J2EPSoFvIn0IB+E3gNcyYn9i3gUDnJOg6PZBa04SP5uS+gwWU7WJE3tNhuE26TG2j49iM0= X-Received: by 2002:a05:6a00:170c:b029:225:8851:5b3c with SMTP id h12-20020a056a00170cb029022588515b3cmr15931886pfc.0.1618755606089; Sun, 18 Apr 2021 07:20:06 -0700 (PDT) MIME-Version: 1.0 Date: Sun, 18 Apr 2021 16:19:55 +0200 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000e1122105c03fe834" Subject: [RFC] [Draft] Final constants From: kocsismate90@gmail.com (=?UTF-8?B?TcOhdMOpIEtvY3Npcw==?=) --000000000000e1122105c03fe834 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Internals, I've recently realized that class constant values cannot always be trusted 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 engine 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/8d75920bb04a9be4c73c2a775e= e5766262cf2a0d/lib/Doctrine/ruleset.xml#L123 ), but I'm wondering if it would be better to simply make it possible to allow 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 --000000000000e1122105c03fe834--