我正在尝试运行一个从变量命名的函数。没有语法错误。不返回温度。我不确定问题出在函数本身还是 eval 上。到目前为止,评估主题的变体还没有奏效。
function getBtemp($lum, $sub){
$tempsB = array(
"V" => array( 30000, 25400, ... ),
"III" => array( 29000, 24000, ... ),
"I" => array( 26000, 20800, ... ) );
if($lum == "VI"){ $lum = "V"; }
else if($lum == "IV"){ $lum = "III"; }
else if($lum == "II" || $lum == "Ib" || $lum == "Ia" ){ $lum = "V"; }
return $tempsB['$lum']['$sub']; }
// Variables:
$spectralclass = "B";
$luminosityclass = "V";
$subclass = 5;
// Needed:
$temp = getBtemp($luminosityclass, $subclass);
// Functions are named from spectral class, e.g. get.$spectralclass.temp()
// Attempt:
$str = "$temp = get".$spectralclass."temp($luminosityclass, $subclass);";
eval($str);