I think both that and the test hold things up.
PHP Code:
<?php
function closureTest(){
// static $closure = null;
// if(!isset($closure))
$closure = function(){ return "something\n"; };
return $closure();
}
From my own timings (static vs. nonstatic, checked vs. nonchecked) enabling both or neither are roughly the same, and are significantly better than doing only one.
Then again, how does
PHP Code:
function closure()
{
return "something\n";
}
function closureTest(){
print closure();
}
closureTest();
closureTest();
closureTest();
perform? My point being, that a main strength of closures is that they "close over" variables in their defining scope, so that you can customise the function on the fly. If it has the same body every time you create it you might as well just make it an ordinary function - one with a name that you can refer to it by.
Bookmarks