OOP PHP: Is it okay to store configuration strings in constants?

93 Views Asked by At

I am writing a class to process an associative array. Inside the class, array keys are used in getter/setter like functions.

Since I can't guarantee that the array keys will never change (either technical requirement or simply for convenience), is it okay to use class constants to store the array keys, so that the getter/setter like functions use these instead of a hardcoded array key?

That way, all array keys could be visible in one place in the class which would allow easy change/configuration.

1

There are 1 best solutions below

0
On BEST ANSWER

It is a widespread and perfectly legitimate use of class constants.

So yes, it may "be ok".