相关疑难解决方法(0)

在PHP中模拟命名函数参数,有什么好主意?

如果我编写这样的函数,可以在PHP中模拟命名函数参数

function pythonic(array $kwargs)
{
    extract($kwargs);
    // .. rest of the function body
}

// if params are optional or default values are required
function pythonic(array $kwargs = array('name'=>'Jon skeet'))
{
    extract($kwargs);
    // .. rest of the function body
}
Run Code Online (Sandbox Code Playgroud)

除了在IDE中失去intellisense之外,这种方法的其他可能缺点是什么?

编辑:

安全性:在这种情况下,安全性不应该是非问题,因为提取的变量仅限于功能范围吗?

php function named-parameters

20
推荐指数
3
解决办法
6961
查看次数

标签 统计

function ×1

named-parameters ×1

php ×1