Re: Is there a way to specify class constant's type?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 29.06.2020 at 19:52, Jelly Legend wrote:

> Hi,
>
> I tried using types on class constants which resulted in an error.
> I'm trying to enforce a type of a constant on a child class, which can
> currently be overwritten.
>
> I want to use top abstract classes, a sort of the main data processors
> and its children as configurations.
>
> Example: https://pastebin.com/sWuFTrFr
>
> I find it very clean to use constants for this purpose, but I haven't
> found a way to enforce their type, other than using abstract static
> methods and defining their types and implementations in children.
>
> Example: https://pastebin.com/edit/bGURTbak
>
> The behaviour I expected was that if a class constant's type is
> defined then it's children could not override the type of the constant
> i.e. redefine it but not change its type.
>
> Example: https://pastebin.com/2LrcKjDp
>
> Is there a way to achieve strict types on child constants other than
> using methods?

No, but typed constants have been recently proposed:
<https://externals.io/message/110755>.

--
Christoph M. Becker




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux