Answer the question
In order to leave comments, you need to log in
How to get private const conveniently?
There is a class in which a number of private constants are described.
class Test {
private const ONE = 1;
private const TWO = 2;
...
}
class Test
{
....
public function all()
{
return [
self::ONE => 'один',
self::TWO => 'два'
]
}
public function getOne()
{
return self::ONE;
}
...
}
Answer the question
In order to leave comments, you need to log in
Looks like an enum type.
This library does some of the work for you and adds type checking: https://github.com/myclabs/php-enum
1) Make the constants public, they still cannot be changed. Encapsulation will not be broken.
2) Write wrappers through reflection
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question