有没有一种语法来记录接受单个配置数组而不是单独参数的函数?
我特别考虑 CodeIgniter 风格的库,它使用类似于此的机制:
<?php
//
// Library definition
//
class MyLibrary {
var $foo;
var $bar;
var $baz;
// ... and many more vars...
/* Following is how CodeIgniter documents their built-in libraries,
* which is mostly useless. AFAIK they should be specifying a name
* and description for their @param (which they don't) and omitting
* @return for constructors
*/
/**
* @access public
* @param array
* @return void
*/
function MyLibrary($config = array()) {
foreach ($config as $key => $value) {
$this->$key = $value;
}
}
}
//
// Library usage:
//
// Iniitialize our configuration parameters
$config['foo'] = 'test';
$config['bar'] = 4;
$config['baz'] = array('x', 'y', 'z');
$x = new MyLibrary($config);
?>
所以我的问题是,有没有一种支持的方式来记录配置数组,除了纯文本描述之外?实际上,指定一个适当的@param [type] [name] [desc]
可以让PHPDoc解析出有用的值吗?
另外,CodeIgniter确实只是使用上面通过$config数组传递的值来覆盖自己的值,有效地允许您破坏私有成员。我不是粉丝,但我被困住了。