Nested functions generally shouldn't ever be used. Classes and public/private methods solve the same sorts of problems much more cleanly.
However, function generating functions can be useful:
<?php
# requires php 5.3+
function make_adder($a)
{
return function($b) use($a) {
return $a + $b;
};
}
$plus_one = make_adder(1);
$plus_fortytwo = make_adder(42);
echo $plus_one(3)."\n"; // 4
echo $plus_fortytwo(10)."\n"; // 52
?>
This example is contrived and silly, but this sort of thing can be useful for generating functions used by sorting routines, etc.