Call an anonymous function from another

Manidip Sengupta

I have an anonymous function that works when called directly. However, when I try to call it from another anonymous function, I get the error

Fatal error: Function name must be a string in ...(fileName)

Here is the complete code. Appreciate any thoughts on why this is failing.

<!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>
peterm

You forgot to make $svgCircle available to your second function

$pac = function ($condition) use ($svgCircle) {...};
                             ^^^^^^^^^^^^^^^^

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Call anonymous function from db

From Dev

Is it safe to recursively call one anonymous sub from another?

From Dev

Call anonymous JavaScript function

From Dev

Call anonymous function on object

From Java

Call a function from another file?

From Dev

Call function from another script

From Dev

Call a function from another thread

From Dev

Call a function from an another class

From Dev

Call class method from inside array_map anonymous function

From Dev

Call function from another function Mysql

From Dev

Call a __init__ function from another function

From Dev

how to call a function from another function in Jquery

From Dev

Call function from another function in jQuery OOP

From Dev

How to call a number from another function into a function?

From Dev

How to call from function to another function

From Dev

Call a function from within another function

From Dev

How to call a function from within another function?

From Dev

php call anonymous functions inside anonymous function

From Dev

PHP - Call function from after call to another function in the class

From Dev

Javascript Anonymous function within then call

From Dev

call stack showing anonymous function

From Dev

MDN example of Call on an anonymous function

From Dev

javascript anonymous function call with parameter

From Dev

Call another function from another function C#

From Dev

AngularJS Call function from another file

From Dev

How to call a function from another class in python?

From Dev

Execute function to call performSegueWithIdentifier from another class

From Dev

Call function from another shell script

From Dev

How to call a controller function from another controller?

Related Related

HotTag

Archive