Re: [RFC] First-class callable syntax

From: Date: Thu, 20 May 2021 19:54:16 +0000
Subject: Re: [RFC] First-class callable syntax
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-114546@lists.php.net to get a copy of this message
On 20/05/2021 19:16, Alexandru Pătrănescu wrote:
Also, considering the resolution between property and method (or between constants and static methods) , it's clear that we need a syntax that looks like the usual invocation:(...), or (?), (...?), ($), ($$), (...$) etc.
I'd like to expand on this point, because I'm seeing a lot of suggestions for syntaxes that overlook it. The following are all valid, but refer to _different_ things called "foo": foo // a constant called foo foo() // a function called foo $foo // a variable called foo $bar->foo // a property called foo $bar->foo() // a method called foo Bar::foo // a class constant Bar::foo() // a static method Bar::$foo // a static property The thing that consistently distinguishes function and method calls is the parentheses after them. This holds even for "exotic" combinations: $foo() // a variable called foo, de-referenced as a callable and then invoked ($bar->foo)() // a property called foo, de-referenced as a callable and then invoked foo()() // a function called foo, the return value of which is de-referenced as a callable and invoked Any callable syntax (and, if/when we get one, a partial application syntax) that doesn't have the parentheses there is going to run into annoying edge cases fast. Not necessarily the kind of edge cases that are hard for the parser, but definitely the kind that are confusing to humans. Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#114546) next »