Using magic constants to access object properties

50 Views Asked by At

I am about to load a language object as a property from controller object like this:

$this->lang = new Languages(en)

Inside the methods of my controller object i am currently accessing the specific translation like this:

function = myFunction(){

$magic = __FUNCTION__;
$lang = $this->lang->$magic;

~~ mycode

}

BUT i want something like this to make it "leaner" code:

$lang = $this->lang->__FUNCTION__;

Does anybody know how to use the Magic Constants in object notation properly ? Unfortunately i havent found any answer here or official php.net website

1

There are 1 best solutions below

0
On BEST ANSWER

as @AbraCadaver suggested, $this->lang->{__FUNCTION__} is working