This is a pretty old question, but maybe this answer might help someone else.
You can emulate a public constant that is limited within the class by applying the last keyword to a method that returns the given value, for example:
class Foo {
The final keyword in the method prevents redefining the extension method. You can also put the final keyword before the class declaration, in which case the keyword prevents the class from inheriting.
To get almost what Alex was looking for, you can use the following code:
final class Constants { public MYCONSTANT() { return 'MYCONSTANT_VALUE'; } } class Foo { static public app() { return new Constants(); } }
The emulated constant value will be available as follows:
Foo::app()->MYCONSTANT();
Wouter van Dam Mar 29 '13 at 17:51 2013-03-29 17:51
source share