GeezerVison is showing github.com — short method references · Issue #2 · php-plus/engine
This repository was archived by the owner on Sep 17, 2019. It is now read-only.
This repository was archived by the owner on Sep 17, 2019. It is now read-only.
short method references #2DescriptionSo in PHP we can make a method reference by using this syntax right now
Route::get('users', [UserController::class, 'index']);
I propose that we add a short method reference syntax like so
Route::get('users', UserController::index);
Reacted by Julian Martin, Miguel Piedrafita, Jonathan Nessier, Oliver Nybroe, Marcin Harasim, Luis Canario and Fidel Aquino Reacted by John Pedrie Activitychanged the title [-][RFC] Short method references[/-] [+]short method references[/+] on Sep 11, 2019stancl commented on Sep 11, 2019 Should this work only with static access? It could be problematic with access inside the class because you can have a property and a method with the same name. $this->foo() and ($this->foo)() are different things.
And with static methods, this is already possible. Strings that reference static methods are callable:
>>> class Bar { public static function xyz() { return 'foo'; } }
>>> 'Bar::xyz'();
=> "foo"olivernybroe commented on Sep 11, 2019 @stancl This should work with non static method also. It should not be used for properties, only methods.
As in my example, it would basically just be a wrapper for [Bar::class, 'xyz'], as that syntax also supports static methods.
>>> class Bar { public static function xyz() { return 'foo'; } }
>>> [Bar::class, 'xyz']();
=> "foo"
The only "problem" I really see with it is that the same syntax is used for constants. However in that case, I think the constant should have priority. enumag commented on Sep 12, 2019
The only "problem" I really see with it is that the same syntax is used for constants. However in that case, I think the constant should have priority.
In real world constants are usually written in uppercase and methods in camelcase so it's not a real problem. In my opinion Plus should simply throw an error if a class has both a method and a constant with the same name. Reacted by Oliver Nybroe and Fidel Aquino olivernybroe commented on Sep 12, 2019 @enumag Yeah, I like the idea of just throwing an error. And the uppercase/camelcase scenario was also why I sad "problem" 👍
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|