Jump to content

Anonymous functions in PHP


boen_robot

Recommended Posts

I really like PHP more than JavaScript. However, one thing about JavaScript that I like are anonymous function. That is, create a function at a moment where a callback is expected, like

attachEvent('click', function(e) {/* code handler here */})

In PHP, there are functions that accept callbacks as their arguments. However, I'm wondering, could such functions possibly accept an anonymous function somehow, and how would such function actually be declared within thar argument? A case I'm particularly interested in is array_map, though the question pretty much applies to any function accepting a callback.[edit]Scratch that. I found a solution with the create_function() function. It turns out it can be used as such functions' arguments. [/edit]

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...