i would like to see it done more like javascript with un-named function. instead of:<p><pre><code> $replacement = function ($matches) {
return str_replace ($matches[1], ' ', '&nbsp;').' ';
};
return preg_replace_callback ('/( +) /', $replacement, $text);
</code></pre>
do:<p><pre><code> return preg_replace_callback ('/( +) /', function ($matches) {
return str_replace ($matches[1], ' ', '&nbsp;').' ';
}, $text);
</code></pre>
and also make array_map more like Array.each(e) in js:<p><pre><code> $processed = array_map($array, function($e) {
return strtolower($e);
});
</code></pre>
and all the custom defined functions like usort:<p><pre><code> $processed = usort($array, function($a, $b) {
return $a > $b ? 1 : -1;
});</code></pre>
While I personally think that closures and lexical scoping are desirable feature in any language, this seems a bit like putting lipstick on a pig to me.<p>As a simple wrapper around various C libraries with automatic memory management and higher-level syntax, PHP makes a certain kind of sense, warts and all. As a general-purpose high-level language, I have to wonder exactly what problem it solves that Perl, Ruby, and Python haven't already done better.<p>What do you think the average newbie PHP developer is going to do the first time they encounter a function which closes over a class instance as state, and then returns a lambda?<p>The subtle interplay between reference vs. value calling conventions, PHP's <i>weird</i> scoping rules, and the new 'lexical' keyword seems like a sure source of head-scratching for new developers, too.