Wild-Guessing-mode:
Your function Sum() would "normaly" take two parameters/operands like
function Sum($a, $b) {
return $a+$b;
}
echo Sum(1, 20);
Now you have the function Test() and you want it to return a function fn that takes only one parameter and then calls Sum($a, $b) with one "pre-defined" parameter and the one passed to fn.
That's called either currying or partial application (depending on what exactly you implement) and you can do something like that with lambda functions/closures since php 5.3
<?php
function Sum($a, $b) {
return $a + $b;
}
function foo($a) {
return function($b) use ($a) {
return Sum($a, $b);
};
}
$fn = foo(1) // -> Sum(1, $b);
$fn = foo(2) // -> Sum(2, $b);
echo $fn(47);
function Sumis declared and defined in the global scope just likefunction testis, the definition is only "postponed" untilfunction testis executed. With php 5.3 (as Pekka has mentioned) lambda functions/closures have been introduced. If they are what you're looking for depends on what you're actually trying to achieve.return-statements instead of globals.$b = sum($a, 20);could work just fine.