<html>
<! DynamicFunction2.php                                       >
<! Chapter 7, Oracle Database XE PHP Web Programming          >
<! by Michael McLaughlin                                      >
<!                                                            >
<! This script demonstrates defining an anonymous function    >
<! with two parameters that assigned as a global variable,    >
<! which makes it available after its nested runtime          >
<! execution. The global call places the function in the      >
<! global namespace.                                          >
<head>
<title>
  Chapter 7 : DynamicFunction2.php
</title>
</head>
<body>
<?php
  // Define a set of variables.
  $a = 2;
  $b = 2;
  $c = 4;

  // Call the global function.
  nested($a,$c);

  // Call the anonymous function by its variable name.
  if (isset($add))
    print "[".$add($a,$b)."]";
  else
    print "[\$add is not defined.]";

  // Define a global function.
  function nested($a,$b)
  {
    // Define a script-level variable.
    GLOBAL $add;

    // Define an anonymous function for a script-level variable.
    $add = create_function('$a,$b','return $a + $b;');

    // Call the anonymous function by its variable name.
    if (isset($add))
      print "[".$add($a,$b)."]<br>";
  }
?>
</body>
</html>
