function is_not_numeric($num){
!is_numeric($num);
}
array_map('is_not_numeric', array(1,3,5,'a','c',3));
The fact that php used to take a string as the callback and not an expression is seriously broken.Now (presumably), one can write:
array_map(function($x){ !is_numeric($x) }, array(1,3,5,'a','c',3));
Although, ideally it would be: array_map(!is_numeric, array(1,3,5,'a','c',3));I'm not just PHP-trolling here, either. There is a history in the PHP project of adding features to the language without any reference to how they will be made "safe". The PHP interpreter is notoriously unhelpful at catching even the simplest of bugs. This just seems like another ad-hoc feature added to the list of things that are likely to introduce subtle bugs that are undetectable until they are running on a production system somewhere.
I agree that PHP's house is on fire, but PHP has such a big house that I'm not sure it's noticed yet.
PHP, being the quirky language that it is, needs the use syntax to enable closures for cases where there are dynamic variable references. This is a bad example but illustrates the problem:
$foo = 'bar'; $fun = function() use ($foo) { $var = 'foo'; echo ${$var}; }; $fun(); // output 'bar'
$fun = function() { $var = 'foo'; echo ${$var}; }; $fun(); // fails
Sure, you could close over the entire local namespace but that's an efficiency nightmare and leads to unpredictable code.