Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46819 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97512 invoked from network); 19 Jan 2010 17:59:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2010 17:59:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=jochem@iamjochem.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jochem@iamjochem.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain iamjochem.com from 194.109.193.121 cause and error) X-PHP-List-Original-Sender: jochem@iamjochem.com X-Host-Fingerprint: 194.109.193.121 mx1.moulin.nl Linux 2.6 Received: from [194.109.193.121] ([194.109.193.121:37897] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/DD-29385-4E2F55B4 for ; Tue, 19 Jan 2010 12:59:02 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id 47ACC2BC727; Tue, 19 Jan 2010 18:58:58 +0100 (CET) X-Virus-Scanned: amavisd-new at moulin.nl Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (mx1.moulin.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lB6wGmZfgWw7; Tue, 19 Jan 2010 18:58:51 +0100 (CET) Received: from [192.168.2.105] (i108075.upc-i.chello.nl [62.195.108.75]) by mx1.moulin.nl (Postfix) with ESMTP id 737592BC6D7; Tue, 19 Jan 2010 18:58:51 +0100 (CET) Message-ID: <4B55F2D8.8040203@iamjochem.com> Date: Tue, 19 Jan 2010 18:58:48 +0100 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; nl; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 MIME-Version: 1.0 To: Stanislav Malyshev CC: 'PHP Internals' References: <4B54FC87.8070106@zend.com> In-Reply-To: <4B54FC87.8070106@zend.com> X-Enigmail-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] function call chaining From: jochem@iamjochem.com (Jochem Maas) 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.