Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46816 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88344 invoked from network); 19 Jan 2010 17:39:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2010 17:39:43 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 216.239.58.189 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 216.239.58.189 gv-out-0910.google.com Received: from [216.239.58.189] ([216.239.58.189:1173] helo=gv-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A3/CB-29385-D5EE55B4 for ; Tue, 19 Jan 2010 12:39:43 -0500 Received: by gv-out-0910.google.com with SMTP id n8so79197gve.37 for ; Tue, 19 Jan 2010 09:39:39 -0800 (PST) Received: by 10.103.80.23 with SMTP id h23mr3970260mul.11.1263922778742; Tue, 19 Jan 2010 09:39:38 -0800 (PST) Received: from ?192.168.200.22? (c-98-234-184-167.hsd1.ca.comcast.net [98.234.184.167]) by mx.google.com with ESMTPS id y6sm22993453mug.31.2010.01.19.09.39.36 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 19 Jan 2010 09:39:37 -0800 (PST) Message-ID: <4B55EE56.8040104@lerdorf.com> Date: Tue, 19 Jan 2010 09:39:34 -0800 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) 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: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] function call chaining From: rasmus@lerdorf.com (Rasmus Lerdorf) Stanislav Malyshev wrote: > 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? I don't mind the foo()() syntax, especially now that we have closures. But people are right, we have a longstanding feature request for $foo()[0] as well, so if we start down this path of adding chaining, we should do that one as well and see if any others make sense. I do think the syntax is a bit ugly, but I also think it is clear what it does and doesn't obscure/mislead the semantics of the call the way the (new foo)->bar() suggestion does. Not sure the {} expression syntax is needed. What sort of expressions do you see being useful here that would need the braces? Stuff like $a[$idx]() works today without needing any extra syntax. Are you thinking along the lines of: {strtolower($a[$idx])}() or something like that? That would make the "I hate linefeeds and semi-colons" crowd happy, I guess. -Rasmus