是否有用于记录采用单个配置数组而不是单个参数的函数的语法?
我正在特别考虑 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 数组传入的值覆盖了它自己的值,从而有效地允许您破坏私有成员。我不是粉丝,但我坚持下去。