I want to save php code in my database and then use it in my script.
class A {
public function getName() {
return "lux";
}
}
$a = new A();
My database has data such as
"hello {$a->getName()}, how are you ?"
In my php code, I am loading data into the $ string variable
$string = load_data_from_db();
echo $string;
So now the line $ contains "hello {$ a-> getName ()}, how are you?"
{$ a-> getName ()} is still not interpreted
Question: I cannot find how to write the rest of the code so that {$ a-> getName ()} is interpreted "in hello lux, like you." Can anyone help?
$new_string = ??????
echo $new_string;
Is there a solution with eval ()? (please not debate about evil eval;)) Or any other solution?
source
share