php invoke class instance from dynamically generated string
<p>lets say I have a class named 'translations'.
I have an instance of the class called 'chinese_translations'</p>

<pre><code>$chinese_translations = new translations;
</code></pre>

<p>Afterwards, I want to call this instance from a dynamically built string and I have tried several ways:</p>

<pre><code>$part1 = 'chinese_';
$part2 = 'translations';
$instance_of_translations = ${$part1.$part2};
$instance_of_translations-&gt;getMsg();//Doesn't work
</code></pre>

<p>Also like this:</p>

<pre><code>$part1 = 'chinese_';
$part2 = 'translations';
$instance_of_translations = $part1.$part2;
$$instance_of_translations-&gt;getMsg();//Doesn't work
</code></pre>

<p>I always get the "Call to a member function getMsg() on a non-object" message.
What I'm doing wrong?</p>

<p>*SOME ACTIONS TAKEN AND RESULTS OBTAINED:</p>

<pre><code>//Lets see if the var is in scope:

echo $chinese_translations-&gt;getMsg(get_locale());//It works

$instance_of_translations = ${$part1.$part2};//Let's try to build the name dynamically

echo $chinese_translations-&gt;getMsg(get_locale()); //Call to a member function getMsg() on a non-object

echo $$chinese_translations-&gt;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"]=&gt; array(2) { ["es_ES"]=&gt; string(19) "The expected result" ["it_IT"]=&gt; string(19) "The expected result" } }NULL
</code></pre>