lets say I have a class named 'translations'. I have an instance of the class called 'chinese_translations'
$chinese_translations = new translations;
Afterwards, I want to call this instance from a dynamically built string and I have tried several ways:
$part1 = 'chinese_';
$part2 = 'translations';
$instance_of_translations = ${$part1.$part2};
$instance_of_translations->getMsg();//Doesn't work
Also like this:
$part1 = 'chinese_';
$part2 = 'translations';
$instance_of_translations = $part1.$part2;
$$instance_of_translations->getMsg();//Doesn't work
I always get the "Call to a member function getMsg() on a non-object" message. What I'm doing wrong?
*SOME ACTIONS TAKEN AND RESULTS OBTAINED:
//Lets see if the var is in scope:
echo $chinese_translations->getMsg(get_locale());//It works
$instance_of_translations = ${$part1.$part2};//Let's try to build the name dynamically
echo $chinese_translations->getMsg(get_locale()); //Call to a member function getMsg() on a non-object
echo $$chinese_translations->getMsg(get_locale()); //Object of class internal_message could not be converted to string in
var_dump($instance_of_translations);//It throws the following:
//object(internal_message)#1956 (1) { ["message"]=> array(2) { ["es_ES"]=> string(19) "The expected result" ["it_IT"]=> string(19) "The expected result" } }NULL
$chinese_translationsis in the same scope like the part where you are callinggetMsg()?