Anonymous Functions in PHP

Anonymous functions to make their way into PHP? I'd like it. (via)

Published May 20, 2007
Categorized as Quick Links
Short URL: https://snook.ca/s/804

Conversation

3 Comments · RSS feed
Pat said on May 20, 2007

lol, what I like is the following quote by the guy who is implementing it:

"However, his real question was whether anonymous functions should be part of PHP at all."

Either way, I would like to see this as well.

Michael Jackson said on May 20, 2007

Would be nice to use in something like:

$my_var = preg_replace_callback($regex, function(match){
  return strtolower(match[0]);
}, $string);

Wow...that looks a lot like JavaScript.

CTAPbIu_MABP said on May 21, 2007

Great news
i'd like also to have a way to add anonymous func to null object


$obj = (object) NULL;
// or tha same - $obj = new stdClass();

now i can add properties to this object


$value = 'string';
$obj->properties = $value;

but i cant add methods like this


$obj->method = create_function('','return 'this is class method';');

it will be very use full to create objects on fly in this way.

Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.

Want to learn about scaling CSS for large projects?

I'm available for full and half-day workshops on scalable CSS architecture. I can provide on-site training for your team. Interested?
Get in touch.