Re: Typed constants revisited

From: Date: Fri, 25 Mar 2022 12:35:01 +0000
Subject: Re: Typed constants revisited
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-117425@lists.php.net to get a copy of this message
Hi Mark, On Wed, Mar 23, 2022 at 11:55 PM Mark Niebergall <mbniebergall@gmail.com> 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;" ? Regards, -- Guilliam Xavier

« previous php.internals (#117425) next »