Re: function call chaining

From: Date: Tue, 19 Jan 2010 17:58:48 +0000
Subject: Re: function call chaining
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-46819@lists.php.net to get a copy of this message
Op 1/19/10 1:27 AM, Stanislav Malyshev schreef: > Hi! > > I wrote a small patch that enables this kind of syntax in PHP: > > foo()(); > > What it means is that if foo() returns callable value (which probably > should be function name or closure) then it would be called. Parameters > and more than two sets of () work too. > Of course, this is mostly useful for doing closures, and that was > primary drive for implementing it - to make working with closures and > especially function returning closures easier. > What does not work currently is $foo->bar()() - since it is surprisingly > hard to tell parser it's not {$foo->bar}()() - which of course is not > what I want to do. > > The patch is here: http://random-bits-of.info/funcfunc.diff > > What do you think? If somebody has better idea btw - maybe make > something like {foo()}() - and make that work for any expression inside > {} - that might work too. So, what do you think? cool as ice! :-) I do worry how many painful edge cases this throw up and additionally how many beginner coders with a bit of JS experience would continuely complain/moan/question why PHP didn't work they [think] JS works, for instance the classic JS closure-type tricks, e.g.: doIt = function(a, b) { return function() { return b(a);} } func = (function() { var bar = ''; return function(foo) { doIt(foo, bar)(); } })(); document.write(func(function(a) { return a + '-fooey'; })); it's quite obvious how easy it is to make javascript code very difficult to follow, personally I love it, but using it sensibly requires alot of care and attention, it's worth considering whether giving PHPer another very powerful gun is wise choice ... especially given how often they/we/(me!) put holes in feet. I can imagine you'd be opening yourself up for sleepless night and lots of unwarranted abuse for having offered a new bit of greatness. given that Closures are still in their relative infancy (mostly in the context of production use) and the fact that this is liable to still of itself be in flux, and additionally the mountain of work/details (AFAIKT) required for PHP6, that, maybe, such functionality should be put on the backburner for now. at some stage all the new stuff (most notably Closures) will stabalize to such a degree that it would become more manageable to introduce such a thing. just my 2 cents.

« previous php.internals (#46819) next »