I use eval()
in my current project like this:
if (class_exists($class_name)) //$class_name depends on user input
eval($class_name.'::MyStaticMethod()');
eval()
is executed if and only if class with the name $class_name
exists so it's kinda safe, but I still don't think that this is the best solution.
Can I do the same what code above does without eval()
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…