How can I implement the named argument feature in PHP 7+?
The ideal syntax is:
find($wildcard, relative = true, listIfEmpty = false) {
...
}
But there is no solution to do like that. In the answer, I implemented the shortest possible solution that supports:
- Refactoring
- Type Hints for the params and function result
- Reusable param set
- Typesafe params
- Default values for params
- Getter for each param ( no hard-coded string )
- Very simple setter/getter that you need to change just one name for every param
See the answer for more information and implementation
Do it one in your Framework or globally:
Do it for each function that required named arguments with proper names:
Write your function using this feature:
Finally, use it with the simplest interface: