Some languages allow us to name parameters when passing them to methods, e.g.:
private static function hello(a, long, list = 0, of = 0, parameters = 0)
{
...
}
self::hello(a=1, long=2, list=3, of=4);
It certainly simplifies reading code in some cases. Is there a similar functionality in php?
The most simple construction that I could imagine is:
self::hello(/*a*/ 1, /*long*/ 2, /*list*/ 3, /*of*/ 4);
[offtopic]Love Obj C… It requires to name parameters:[self helloA:1 long:2 list:3 of:4];[/offtopic]
PHP does not provide such functionality but it can be faked to a large degree of realism. I just wrote this thing. Not 100% tested but if used correctly, it will work.
Example of how you use it:
It uses
\in front of classes as it’s namespaced code intended for use with PHP 5.3 or later. Remove the\to try to use it in 5.2, but no guarantees.Here is the code: