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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to