Create anonymous functions with create_function, like create_function('$a,$b','return ' . ($reverse ? '-' : '') . 'strcasecmp($a,$b)')
As you can see, you can reference outside variables. Not elegant, and not the easiest to write (either as I showed or using double quotes and escaping inside variable $), but does the job.
You can use anonymous functions for functions like array_map, array_filter, array_reduce, array_walk, array_walk_recursive, usort, and other functions (possibly your own) expecting or returning a callback. You can invoke variable functions like $x(lol).
Name:
Anonymous2006-04-07 4:28
Just use Ruby or Lisp.
Name:
Anonymous2006-04-07 6:07
>>14
Just STFU. I have yet to see how can you do web applications in LISP, and Ruby is alright but there's far more support and existing open sauce for PHP. (The fact it's simpler helps, but it also hurts because some PHP "programmers" suck, so I'm not counting it as an advantage or a disadvantage.)
Name:
Anonymous2006-04-07 6:18
An anonymous function isn't a closure. I don't know why so many people mix them up.
Name:
Anonymous2006-04-07 6:23
Talking about which, that's a really ugly way to make an anonymous fuction. Is that really an anonymous function...?
Name:
Anonymous2006-04-07 7:05
PHP is the java of web programming.
Name:
Anonymous2006-04-07 7:32
>>18
Not really. It lets you get stuff done without having to make a massive class hierarchy. It's kinda sucky, encourages bad style and attracts wannabe programmers who can't write decent code to save their life. I'd say it's the VB of web programming. Java would be the Java of web programming.
Name:
Anonymous2006-04-07 7:36
>>17
Yes, it is. create_function defines it on the fly and returns a name you can later call as $f(x). This name is a random string.
Name:
Anonymous2006-04-07 8:12 (sage)
Beware! This is merely a convenience function that generates a unique name for a regular function. It is *not* a closure or even an anonymous function. It is just a regular function that gets named for you.
Name:
Anonymous2006-04-07 9:52
>>21
Uh, you don't seem to understand how PHP functions work. They are passed by name. Name as in, a string with the function name. They are called by name too. You _need_ to generate a name to use your anonymous function, because that's what high-order functions use and expect. And yes, as far as you're concerned they are anonymous functions, just like other language's anonymous functions still have an address. The internal name is used to access its code just like addresses, and if you don't mess with addresses you don't mess with random generated names.
Name:
Anonymous2006-04-07 10:40
You _need_ to generate a name to use your anonymous function
lol php
>>29
I did suggest Lisp. These days I generally suggest Ruby as well, since people seem to have a parenthesis phobia and need some cuddly syntax to hold.
Name:
Anonymous2006-04-07 15:51
So I herd u like lisp
Name:
Anonymous2006-04-07 19:23
(equal '(everybody loves Lisp) t)
Name:
Anonymous2006-04-07 19:29
There's one Lisp lover in this thread making so much noise. He got to lean Lisp, so his e-peenor is enormous.
>>35
All you can answer is some trolling link you found on the internet instead of thinking for yourself? That's pathetic in front of those who know why Lisp is superior to what is available today. Your inability to write clean and simple frameworks must be why you haven't answered my previous post.
>>41 vb of web programming? sigh, and what exactly, pray tell, is that?
We were talking about PHP. Pay attention, I know ADD is a debilitating disorder that afflicts many 13 year olds, but you're gonna have to deal with it.
>>46-48
If you can't do PHP, you really have a problem pal.
Name:
Anonymous2006-04-10 8:47
>>49
It's not "can't do" it's "really really really don't want to do."
Name:
Anonymous2006-04-10 9:32
PHP: Hippy Programming
Name:
Anonymous2006-04-10 9:35
>>40
You're pretty stupid if you can't understand (function *arguments)
Name:
Anonymous2006-04-10 9:48
>>52
You're pretty clever if you can grok ((((((((((((((((((((((((((((()))))))))))))))))))))))))))))(((((((((((((((((((((((((((((((())))))))))))))))))))((((((((((((((((((((((((()))))))))))))))
Name:
Anonymous2006-04-10 10:02
>>53
You're pretty dumb if you think that's what Lisp code looks like.
>>50
Which means you can't do it properly. Lame. I guess if you learnt Lisp you could write proper PHP applications, but you probably haven't given the language a chance, just took a quick look at some existing code and said "this sucks".
Name:
Anonymous2006-04-11 18:53
>>56
You've never worked with other programmers before have you.
Name:
Anonymous2006-04-11 20:02
>>56
You've never worked on a major programme before have you?
Fixed.
Name:
Anonymous2006-04-12 5:59
Yes, currently working with an open sauce one that has hundreds of thousands of lines of code, most of it is alright.
Name:
Anonymous2006-04-12 7:09
>>59
Open-sauce ain't no enterprise quality, so it doesn't countなの.
Programming is the magic of these modern times. The art of manipulating machinery that processes information. Ask any random fool on the street and it's all black boxes and unknowables to them.
Name:
Anonymous2008-04-19 19:01
>>15
You can use call/cc in scheme to write web apps