Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道可以嵌套数组或对象并像这样访问它们:
some_array["sub_type1"]["value"]
或者
some_object->sub_type1->value
但是是否也可以使用某种嵌套的常量值并像这样访问它们?
SOME_CLASS::SUB_TYPE::MORE_SUBTYPES::VALUE
为您的子类型使用类继承,并在相应的子类型类定义中定义常量。
<?php class Someclass {} class Someclass_Subtype extends Someclass {} class Someclass_Subtype_Child extends Someclass_Subtype { const VALUE = 'whatever'; }