Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117432 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6926 invoked from network); 25 Mar 2022 17:25:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2022 17:25:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C2F101804C3 for ; Fri, 25 Mar 2022 11:53:04 -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_20,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, 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-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 11:53:04 -0700 (PDT) Received: by mail-ej1-f43.google.com with SMTP id j15so17085953eje.9 for ; Fri, 25 Mar 2022 11:53:04 -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=p2Dw3mPfAJIIYicPc4lGAV3zst/7MTGNTf2PIBweJ6Y=; b=qhe+VB0iJqgiMt3gcGhxPBSCVxFgtTaDW8Bf71VATLvTv3XcXz7pjfG1IcFY9XCmTd V75OumCHv8rK+Ae9YcOaaZLjFHiDtobtQrFPKa/PqkY8pIyyaEjzB6kh8Oe3/U33s+DF L41I5Ln+ltnD7hNad9uSDZ/biTaPryKPoeen4VK2ZtM1H5qY1KLlKA92H3cduNcczLLO QBdexaEPZqrh23akVPwI6antceGpOLM8s6bOBksZsHOEKxXO9G3Bwp5Soa7jjANiTFD+ P2scJn6c58jkLILTOTSd9LuYEEZuTRTkefOlQudOJduUlD4nDbdBzClsE1cESc8ot/RO Dp4w== 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=p2Dw3mPfAJIIYicPc4lGAV3zst/7MTGNTf2PIBweJ6Y=; b=D2+f6y8RWREp4WcXWFW1l1YnDHipzZL0BocfDczUTOmipFa3P3dzWvtpTOzeti9i94 hCv47aU3UkXSrls2L+St9zm8UglZr0+FlgXG8Z1jg6VU1309li5tbczeKtavHMHuMNTh zkGyGdD98b+hgprxpOnzqGzqB/eW34Jc0VX/rDAlzO3nZWai9ZJBeD3JKY5Ow8DgZzNZ 1hAqr2+78P1iPOruQHWu5caBIACwOQ4nqoWV81J4nsZAqtJt4FCORTkDV78Eba2mz1Op 6HVqkeHcX19hbk0b79tXCZbAJi/xXXGcaexSLcwDjbDW6airHOVf6bXtwFDYgwMFINZz 84RQ== X-Gm-Message-State: AOAM530U/SQMoUXdOZnyXOeOKAxBHJdWh/njDsL/5/9OMlz2y3YwH/ij C/d4srsldzbTT9KO5yePyGi0BcmLgbDT1UjEH+8LbEv8 X-Google-Smtp-Source: ABdhPJzIBI4FztLSDMxKqNjMX6EsvEWUW8iuJR7c3E+4FCleXZJWrgR57vzpqCLvcEe2PkHup3YvJox6KvBIgzDsBuc= X-Received: by 2002:a17:907:2cc2:b0:6df:e348:7f16 with SMTP id hg2-20020a1709072cc200b006dfe3487f16mr13666145ejc.172.1648234382817; Fri, 25 Mar 2022 11:53:02 -0700 (PDT) MIME-Version: 1.0 References: <76c399cb-fb29-4583-a212-8eb69740c96b@www.fastmail.com> In-Reply-To: Date: Fri, 25 Mar 2022 12:52:51 -0600 Message-ID: To: Guilliam Xavier Cc: php internals Content-Type: multipart/alternative; boundary="000000000000e4fca205db0f786e" Subject: Re: [PHP-DEV] Typed constants revisited From: mbniebergall@gmail.com (Mark Niebergall) --000000000000e4fca205db0f786e Content-Type: text/plain; charset="UTF-8" On Fri, Mar 25, 2022 at 10:55 AM Guilliam Xavier wrote: > 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. >> > > I understand, but note that methods are implicitly abstract in an > interface, but it must be explicit in an abstract class; and since I see > the proposed feature mainly as a "replacement" for abstract static methods > [whose all implementations just return a literal value]... (anyway, not > super important) > Constants are not abstract in an interface - they must be assigned a value. Only classes and methods can be abstract. Within an abstract class it is not valid to have an abstract property. Properties can be defined `protected int $id;` and optionally assigned a value `protected int $id = 5;`, but cannot be `abstract protected int $id;`. So to me it makes more sense to have constants follow the same syntax as properties `public const bool CAN_FLY;` without the `abstract` keyword. An example: ``` abstract class Bird { public const bool CAN_FLY; protected bool $isExtinct; ``` This allows for similar behavior, similar requirements, and similar syntax - consistency ftw! There seems to be interest and good use cases (thanks Sara for the good practical example!). At this point I'm going to work on a new RFC with all the details and feedback from this discussion. --000000000000e4fca205db0f786e--