<?php
class a{
public function func(){
return "a";
}
}
class b{
public function func(){
return "b";
}
}
$input = "a"; // Would come from user input
eval('$duck = new '.$input.'();');
$duck->func(); // Returns a in this case
有什麼辦法,我可以做到這一點,而無需使用eval()
?
請參閱此:http://stackoverflow.com/questions/951373/ when-is-eval-evil-in-php –