Re: function call chaining

From: Date: Tue, 19 Jan 2010 07:14:34 +0000
Subject: Re: function call chaining
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-46792@lists.php.net to get a copy of this message
On 19.01.2010, at 3:27, 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. I like it! regarding $foo->bar()()… is it possible to use precedence rules here? something like: ($foo->bar())(); > 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? why curly braces? Parentheses would feel more natural here. Would be nice if something like this worked too: (new Class())->method();

« previous php.internals (#46792) next »