我有一个匿名函数,直接调用时可以正常工作。但是,当我尝试从另一个匿名函数调用它时,我收到错误
致命错误:函数名称必须是...(fileName)
中的字符串这是完整的代码。感谢任何有关失败原因的想法。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
$ringW = 16; $ringCx = 8;
$ringH = 16; $ringCy = 8; $ringR = 7;
$penWidth = 2;
$svgCircle = function ($fillColor, $ringColor)
use ($ringW, $ringH, $ringR, $ringCx, $ringCy, $penWidth) {
echo "<svg width=\"$ringW\" height=\"$ringH\">";
echo "<circle cx=\"$ringCx\" cy=\"$ringCy\" r=\"$ringR\" " .
"stroke=\"$ringColor\" stroke-width=\"$penWidth\" fill=\"$fillColor\" />\n";
echo "</svg>\n";
};
$pac = function ($condition) {
if ($condition)
// echo "Hello world\n"; // pass
$svgCircle("yellow", "green"); // fails
};
?>
<head>
<title>LVCC Algorithm</title>
</head>
<body>
<?php
$pac(1);
$svgCircle("yellow", "green"); // pass
$svgCircle("yellow", "green");
?>
</body>
</html>
答案 0 :(得分:1)
您忘了将$svgCircle
提供给您的第二个功能
$pac = function ($condition) use ($svgCircle) {...};
^^^^^^^^^^^^^^^^