0

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
    `$lang = $this->lang->{__FUNCTION__}();` maybe? Or if you really wanted a property `$lang = $this->lang->{__FUNCTION__};` Never tested. – AbraCadaver Jun 24 '19 at 21:28
  • `$this->lang->{__FUNCTION__}` did work ! Thank you very much –  Jun 25 '19 at 07:13

1 Answers1

0

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