In the php 7 docs, there's http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.variable-handling.indirect.
I'm trying to use this to call property dynamically. This code only prints v1. I want it to print v1pqrxyz
How can I do that? I'm using PHP version 7.0
class test{
public $v1 = "v1";
public function f1($a){
return $a;
}
public function f2($b){
return $b;
}
}
$test1 = new test();
$arr = ['v1', 'f1("pqr")', 'f2("xyz")'];
foreach ($arr as $value) {
echo $test1->{$value};
}
evalor regular expressions to handle string expressions like'f1("pqr")'. Both are unsafe and/or error prone. You should not do it. Whenever possible use['v1', ['f1', ['arg1', 'arg2']], 'v2']instead.