是否存在用於記錄採用單個配置數組而不是單個參數的函數的語法?用於可變長度參數數組的PHPDoc
我特別想笨樣式庫,它使用類似這樣的機制:
<?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);
?>
所以我的問題是,是否有記錄配置陣列不僅僅是純文本的一些supprted方式描述?其實指定一個合適的@param [type] [name] [desc]
允許PHPDoc解析出有用的值?另外,CodeIgniter實際上只是用上面通過$ config數組傳入的值覆蓋它自己的值,從而有效地允許您打開私有成員。我不是粉絲,但我堅持不懈。
如果可以的話,我會避免它,不幸的是,CodeIgniter的慣例要求使用這種粗糙的配置數組,而不是使用常規的舊參數。 – meagar 2010-01-05 21:17:38
@meagar:是的,我猜/理解,但無法抗拒^^(如果其他人有一天會到達這個問題/答案,這可能會有所幫助) – 2010-01-05 21:18:36
這與我的做法相似。 PHPDoc將採用該列表並將其添加到文檔中,就像任何其他字符串一樣,所以它比沒有任何更好。雖然PDT無法理解它。它只會知道它是一個數組。 – Gordon 2010-01-05 21:21:30