Suggestion Method Constant

  100883
October 12, 2017 17:43 mathiasgrimm@gmail.com (Mathias Grimm)
I would like to suggest a method constant that could be used the same way
we use the ::class one

I don't have a strong personal preference but it could be something like:

MyController::myActionMethod::method, no sure about the internals but it
would be consistent with the one for the class.

Cheers,
  100885
October 12, 2017 18:24 michaeldoehler@me.com (=?utf-8?Q?Michael_D=C3=B6hler?=)
Hi,

Same i have in mind, for example: MyClass@myMethod

To make also some method call routing easier, e.g. in userland routers.

Transform the current approach:

$app->get("/foo", [MyClass::class, "myMethod"]);

To:

$app->get("/foo", MyClass@myMethod);

This will ease a lot, e.g. for refactoring, IDE usage and completes the code as configuration approach for PHP.

Thanks
Michael

> Am 12.10.2017 um 19:43 schrieb Mathias Grimm <mathiasgrimm@gmail.com>: > > I would like to suggest a method constant that could be used the same way > we use the ::class one > > I don't have a strong personal preference but it could be something like: > > MyController::myActionMethod::method, no sure about the internals but it > would be consistent with the one for the class. > > Cheers,
  100897
October 14, 2017 01:02 ajf@ajf.me (Andrea Faulds)
Hi Mathias,

Mathias Grimm wrote:
> I would like to suggest a method constant that could be used the same way > we use the ::class one > > I don't have a strong personal preference but it could be something like: > > MyController::myActionMethod::method, no sure about the internals but it > would be consistent with the one for the class. > > Cheers, >
I've long wanted to make constant lookups fall back to a closure of the correspondingly-named function, where one exists. so `strlen` would resolve to a closure of strlen(). Thing is that classes are weird. We sort of have three different things with sometimes-similar syntax: constants, methods and properties. foo::bar is a constant, foo::bar() is a function, $foo->bar() is a function, but $foo->bar is not a constant. So, if I want $foo->bar to resolve to a method, then $foo::$bar should too, even though that makes no sense. The PHP static property syntax is the bane of my existence. -- Andrea Faulds https://ajf.me/
  100898
October 14, 2017 10:41 michaeldoehler@me.com (=?utf-8?Q?Michael_D=C3=B6hler?=)
Hi,

maybe the introduce of a complete new syntax for method references would solve the issues? Maybe coming back to e.g. "#" ("@" is still used for supressing errors,...)?

As mentions before all kinds can be simplified or? See:

MyClass#myMethod

#function

This should resolve in an object as mentioned before, in this object you have further informations, e.g.

$ref = MyClass#myMethod;
$ref->isStatic();
....

I think an seperate solution for method/Funktion references is more realistic than changing core things...

Greetings
Michael 

> Am 14.10.2017 um 03:02 schrieb Andrea Faulds <ajf@ajf.me>: > > Hi Mathias, > > Mathias Grimm wrote: >> I would like to suggest a method constant that could be used the same way >> we use the ::class one >> >> I don't have a strong personal preference but it could be something like: >> >> MyController::myActionMethod::method, no sure about the internals but it >> would be consistent with the one for the class. >> >> Cheers, > > I've long wanted to make constant lookups fall back to a closure of the correspondingly-named function, where one exists. so `strlen` would resolve to a closure of strlen(). > > Thing is that classes are weird. We sort of have three different things with sometimes-similar syntax: constants, methods and properties. foo::bar is a constant, foo::bar() is a function, $foo->bar() is a function, but $foo->bar is not a constant. So, if I want $foo->bar to resolve to a method, then $foo::$bar should too, even though that makes no sense. The PHP static property syntax is the bane of my existence. > > -- > Andrea Faulds > https://ajf.me/ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
  100899
October 14, 2017 11:00 me@kelunik.com (Niklas Keller)
> > Hi Mathias, > > > Mathias Grimm wrote: > >> I would like to suggest a method constant that could be used the same way >> we use the ::class one >> >> I don't have a strong personal preference but it could be something like: >> >> MyController::myActionMethod::method, no sure about the internals but it >> would be consistent with the one for the class. >> >> Cheers, >> >> > I've long wanted to make constant lookups fall back to a closure of the > correspondingly-named function, where one exists. so `strlen` would resolve > to a closure of strlen(). > > Thing is that classes are weird. We sort of have three different things > with sometimes-similar syntax: constants, methods and properties. foo::bar > is a constant, foo::bar() is a function, $foo->bar() is a function, but > $foo->bar is not a constant. So, if I want $foo->bar to resolve to a > method, then $foo::$bar should too, even though that makes no sense. The > PHP static property syntax is the bane of my existence.
Please no fallbacks, thanks. It was already a mistake for namespaced functions. Regards, Niklas
  100901
October 15, 2017 19:10 ajf@ajf.me (Andrea Faulds)
Hi Niklas,

Niklas Keller wrote:
>> >> Hi Mathias, >> >> >> Mathias Grimm wrote: >> >>> I would like to suggest a method constant that could be used the same way >>> we use the ::class one >>> >>> I don't have a strong personal preference but it could be something like: >>> >>> MyController::myActionMethod::method, no sure about the internals but it >>> would be consistent with the one for the class. >>> >>> Cheers, >>> >>> >> I've long wanted to make constant lookups fall back to a closure of the >> correspondingly-named function, where one exists. so `strlen` would resolve >> to a closure of strlen(). >> >> Thing is that classes are weird. We sort of have three different things >> with sometimes-similar syntax: constants, methods and properties. foo::bar >> is a constant, foo::bar() is a function, $foo->bar() is a function, but >> $foo->bar is not a constant. So, if I want $foo->bar to resolve to a >> method, then $foo::$bar should too, even though that makes no sense. The >> PHP static property syntax is the bane of my existence. > > > Please no fallbacks, thanks. It was already a mistake for namespaced > functions.
I'm not exactly a huge fan of fallbacks myself. If we were to have such a fallback, I'd like to deprecate overlapping method/property/constant names and throw warnings to that effect, with an obvious goal of eventually merging those namespaces. …hey, if we merged properties and constants together, you could do Foo::bar = $baz; instead of having to use the annoyingly inconsistent Foo::$bar syntax. I'd love that. -- Andrea Faulds https://ajf.me/