Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117428 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94946 invoked from network); 25 Mar 2022 15:00:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2022 15:00:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 871D41804AF for ; Fri, 25 Mar 2022 09:27:18 -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.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 ; Fri, 25 Mar 2022 09:27:18 -0700 (PDT) Received: by mail-ej1-f45.google.com with SMTP id yy13so16429254ejb.2 for ; Fri, 25 Mar 2022 09:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2OFTSEWXai9l1oGpqKNdjnedmV3tKszTKXEOkf9lYlM=; b=RkjLi9O8YJxNZql4B2dB2VKgdibaI9KDxXGKVq0P3Q3DhpWJt8hpDM/zorLnDubt7n vbURQ4L1VOZ1bIc3o9SCEEaqYm0yeuwxxxe/zHOYgS49/WxpMySnWPqLAaNKo4qLMYSx RndQUuZaFl0w2ki0WpPXznlxzxgVNBGjqfwTfbvuB6s5ZDxSrA8JVLH9YQTIvdR7zq2J mnv7imdETNno3+tPcpwL6i7sqI03qIkkS0g4vfN1WmlkS+ZQGXyzYR9AvoCZR9Yl2bdu 13hlBt86WKS7mFQLNowp687m6GkrV+b7GNr2tXnV1x7eyzjDB+mTwKkw4hi8tepr9n4R iYSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2OFTSEWXai9l1oGpqKNdjnedmV3tKszTKXEOkf9lYlM=; b=3DnHyEDCRzGMh4DwAuueEe5pWMMisV6re+IRcXSu/FxOZwVmPxlklwAhpGQmi3q10F zOYz1QdlfrCmVQRlp42J/WgsCfYCweO5EfAPPFuGTrXtBhm83NypU2rBJHw4chBX9nRQ 9pZb2XKaLatPG5omxlnDie+G7Wxr4TQAHOXmtbPPuRTuU34bweutXPv+s7Ckmr7kxna1 HJn1gPR7QkhWvP6tXO2fbIELyF4NCc8G/4KIB+1XoVdUfCI/YFhau4IPYZs7MQg+Tl5I Nlhs3sZ6rYdOLq5SCr0mCMvbHTSTTOG3BNAHKjAScEvEGUWEBZ7Kjx9Vv+wZi6w0EWUI +Umw== X-Gm-Message-State: AOAM531gXrlqAkzlV/DpWf3adqxRDSoG8i3OfCUV83ZLuXGn6AZ5sEVj 2JzN6Pl95+4O7ZGIHfN16VYPKnloamSvPVGXJs8= X-Google-Smtp-Source: ABdhPJw+nA+ATcMWW3V3FWVKzqBVPO3qAYF1alhuFE3ajkc2RU0K54Mo2wxmLKdTk67qmT7cBq/4DIHC/7ygv9ILIic= X-Received: by 2002:a17:907:2cc3:b0:6da:e6cb:2efa with SMTP id hg3-20020a1709072cc300b006dae6cb2efamr12367476ejc.169.1648225636319; Fri, 25 Mar 2022 09:27:16 -0700 (PDT) MIME-Version: 1.0 References: <76c399cb-fb29-4583-a212-8eb69740c96b@www.fastmail.com> In-Reply-To: Date: Fri, 25 Mar 2022 10:27:05 -0600 Message-ID: To: Guilliam Xavier Cc: php internals Content-Type: multipart/alternative; boundary="00000000000090080b05db0d6f92" Subject: Re: [PHP-DEV] Typed constants revisited From: mbniebergall@gmail.com (Mark Niebergall) --00000000000090080b05db0d6f92 Content-Type: text/plain; charset="UTF-8" Guilliam, On Fri, Mar 25, 2022 at 6:35 AM Guilliam Xavier wrote: > Hi Mark, > > On Wed, Mar 23, 2022 at 11:55 PM Mark Niebergall > wrote: > >> (...) >> >> Another example I often see in my projects could be used with a similar >> example: >> >> ``` >> abstract class Bird >> { >> public const bool CAN_FLY; >> public const string FAMILY; >> public function canFly(): bool >> { >> return self::CAN_FLY; >> } >> } >> final class EmperorPenguin extends Bird >> { >> public const bool CAN_FLY = false; >> public const string FAMILY = 'penguin'; >> } >> ``` >> > > I had this "need" too (and used abstract static methods where the > implementations just return a literal value...). > > Just 2 remarks: in abstract class Bird, shouldn't it be: > - "*abstract* public const bool CAN_FLY;" (and same for FAMILY) > - "return *static*::CAN_FLY;" > ? > I intentionally left `abstract` out of `public const bool CAN_FLY;` in the `abstract class` for consistency with the implementation with `interface`, which would also have to be `public const bool CAN_FLY;`. Currently `abstract` is only used in front of methods `abstract function doThing(): bool;`. Open to discussion - which way is ideal or preferred? That could be included as a subset of an RFC vote if a consensus during discussion isn't reached. Good correction, yes, `return static::CAN_FLY;` in that example in the concrete child class. > > Regards, > > -- > Guilliam Xavier > --00000000000090080b05db0d6f92--