jayarsee Posted August 31, 2010 Share Posted August 31, 2010 I searched the forums and the Internet as a whole looking for more information on this, but all I've turned up is a lot of information on /how/ to use create_function(), not /when/ to use it. For instance: http://en.wikipedia.org/wiki/Lambda_calculus Let me reiterate that I understand how it works in general. However, in several years of PHP programming, even through the development of fairly complex, robust systems, I can only think of one case where I recall creating a dynamic function and even here I feel like it was a design mistake. Of course, I use anonymous functions all the time in JavaScript for callback code. It seems to be used from time-to-time to iterate over and apply transformations to sets, but I don't understand the advantage over foreach() for such a task. So, if someone is so-inclined, would you mind listing a general scenario or two where create_function() is the correct and appropriate solution to the problem? Link to comment https://forums.phpfreaks.com/topic/212139-what-types-of-problems-are-appropriately-solved-by-create_function/ Share on other sites More sharing options...
RussellReal Posted August 31, 2010 Share Posted August 31, 2010 sorting? Link to comment https://forums.phpfreaks.com/topic/212139-what-types-of-problems-are-appropriately-solved-by-create_function/#findComment-1105474 Share on other sites More sharing options...
btherl Posted August 31, 2010 Share Posted August 31, 2010 usort($KeywordSuggestions, create_function('$a,$b', 'return strcmp($a["vertical_name"], $b["vertical_name"]);')); Here I could have defined a function called "compare_vertical_name()", but it seems like a waste when it's so simple. Creating it inline makes sense to me here. I don't use anonymous functions for anything other than sorting callbacks. If I used preg_replace_callback() I might also use them as callbacks there. Link to comment https://forums.phpfreaks.com/topic/212139-what-types-of-problems-are-appropriately-solved-by-create_function/#findComment-1105475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.