On Tue, Mar 18, 2008 at 12:07 PM, Ray Hauge <ray.hauge.lists@xxxxxxxxx> wrote: > I've been reading up on some of the parts of PHP that has been suggested > could be improved so that I could be more well informed. One of the > more "interesting" (for lack of a better word) suggestions is closures. > I've used closures primarily in JavaScript, and they are handy in that > context, but JavaScript handles events and other more dynamic situations > like that. > > I can't really think of any good examples of why I'd want to use a > closure instead of just calling functions or class methods in PHP. > Variable functions and call_user_func*() have worked for any of the > cases where I did need to be a bit more dynamic. > > I found a great summary of some discussion on the internals mailing list > over here: http://devzone.zend.com/node/view/id/2013#Heading1 > > After reading that article through, I do like Wez's idea of how to > create anonymous functions. The point about it causing confusion with > people coming from other languages definitely applies though. This > article also gives me a second idea for this post. How many people > would want closures in PHP? > > In summary: > > Would you want closures in PHP, and why? not really. in my eyes php primarily has taken on the paradigm of the c-style of programming. eg. c, c++, java. one of the main differences i see compared to java is the allowance of global functions. php does not support multiple inheritance, but in php5 there are interfaces, which afford the multiple inheritance workaround and now i hear talk of these things called traits. as if learning traits wont be weird enough i have gotten quite used to leveraging my experience in the aforementioned languages and also phps dynamic, loosely typed nature. there are a few subtleties of php that bother me but at the end of the day i can live with them. recently i have become proficient w/ javascript. closures, and execution context are starting to make sense and so is the prototype-based object model. i quite like this paradigm and enjoy programming in javascript, but find that many of the things i already understand how to do w/ the php-like object / scope model sometimes difficult to mimic in js. im still learning of course and one day imagine myself being quite good w/ javascript. that said, i believe there are languages that supply 'traditional' oop and the functional model all under the same hood so to speak. at least i know python is essentially that (though i know it lacks ppp) and i think (though dont know for a fact) ruby is something like that [enter greg]. i dont know, i mean sure, php is like this crazy hybrid of so many things, but i just want to master something then start banging out code. the more features that get added the more i will have to know when i do code reviews for my developers [gray hairs appearing on chin...]. does the syntax for create_function() suck, yes.. will just syntactic sugar solve the problem, no; why because as per the article its really all or nothing. being able to pass around the php psuedo type callback is good enough at this point. in short, functional programming support would have been great in php if it had been incorporated early on, at this point i can live without it. if we were going to see support for anything anonymous that i would welcome it would be anonymous objects and the ability to create an object on the fly from an interface as per java 5. o and inner classes would be nice too, but maybe traits would address that desire, i dont know. -nathan