.
if( !function_exists('baz') )
{
function baz( $args ){
echo $args;
}
}
, .
create_function, DONT, , , free() 'd php eval().
, PHP5.3, "" http://wiki.php.net/rfc/closures
if( !isset( $baz ) )
{
$baz = function( $args )
{
echo $args;
}
}
$baz('hello');
$baz = function( $args )
{
echo $args + "world";
}
$baz('hello');
, .
$fname = 'f_first';
function f_first( $even )
{
global $fname;
doExpensiveStuff();
$fname = 'f_others';
$fname( $even );
}
function f_others( $odd )
{
print "<b>".$odd."</b>";
}
foreach( $blah as $i=>$v )
{
$fname($v);
}
, , .
PHP5.3 :
$func = function( $x ) use ( $func )
{
doexpensive();
$func = function( $y )
{
print "<b>".$y."</b>";
}
$func($x);
}
foreach( range(1..200) as $i=>$v )
{
$func( $v );
}
( , , , .;))
,
$data =
doslowthing();
foreach( $data as $i => $v )
{
}
, , . , , :)