functional-php/named-parameters
Composer 安装命令:
composer require functional-php/named-parameters
包简介
Named parameters for functions, methods and constructors.
README 文档
README
It is often useful to be able to call a function or methods using named parameters. For example to only pass a different value for the nth default parameter.
PHP does not allow to do that, this library ought to change that.
Installation
composer require functional-php/named-parameters
Basic Usage
Say you have the following function:
function return_array($a, $b, $c) {
return [$a, $b, $c];
}
Any of the following call is equivalent:
use function FunctionalPHP\NamedParameters\call_user_func_array_np;
// traditional call with positional arguments
call_user_func_array_np('return_array', [1, 2, 3]);
// named arguments in the correct order
call_user_func_array_np('return_array', ['a' => 1, 'b' => 2, 'c' => 3]);
// named arguments in random order
call_user_func_array_np('return_array', ['c' => 3, 'a' => 1, 'b' => 2]);
call_user_func_array_np('return_array', ['c' => 3, 'b' => 2, 'a' => 1]);
Testing
You can run the test suite for the library using:
composer test
A test report will be available in the reports directory.
Contributing
Any contribution welcome :
- Ideas
- Pull requests
- Issues
Inspiration
统计信息
- 总下载量: 6.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-03-18