Tobiasz Cudnik

PHP 5.3 introduces closures and inline functions

In The Net on 25.11.2008 at 0:31

I couldn’t believe it in first place, but there are ongoing works to bring closures power to PHP in upcoming 5.3 version! No more create_function() and backslashing backslashed quotes.

There are also some scope inheritance tries (using “use” keyword). Below you have some teasing snippet, after which head to wiki.php.net/rfc/closures for more…

function replace_in_array ($search, $replacement, $array) {
  $map = function ($text) use ($search, $replacement) {
    if (strpos ($text, $search) > 50) {
      return str_replace ($search, $replacement, $text);
    } else {
      return $text;
    }
  };
  return array_map ($map, $array);
}
  1. [...] jquery, php Some time ago i’ve wrote about new PHP 5.3 closures feature. Today i would like to show you it in action with phpQuery. If [...]