As of PHP 5.3, you can assign an anonymous function to a variable, then unset it:
$upper = function($str) {
return strtoupper($str);
};
echo $upper('test1');
// outputs: TEST1
unset($upper);
echo $upper('test2');
// Notice: Undefined variable: upper
// Fatal error: Function name must be a string
Before 5.3, you can do something similar with create_function()
$func = create_function('$arg', 'return strtoupper($arg);');
echo $func('test1');
unset($func);
$func2 = "lambda_1";
echo $func2('test2.a'), "
"; // Same results, this is the "unset" $func function
echo $func('test2.b'); // Fatal Error
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…