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

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

 



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?

Thank you!

Jelly



[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