【发布时间】:2010-10-15 09:18:05
【问题描述】:
如果我编写这样的函数,可以在 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
}
除了在 IDE 中失去智能感知之外,这种方法还有哪些其他可能的缺点?
编辑:
安全性:在这种情况下安全性不应该不是问题吗,因为提取的变量仅限于函数范围?
【问题讨论】:
标签: php function named-parameters