2010-08-28 26 views
5

如何記錄可變數量的參數?我正在用PHP和JavaScript編寫一個應用程序。目前我有(在JavaScript中):如何記錄可變數量的參數

/** 
* Description 
* @param {String} description 
*/ 
function fn() 
{ 
    // arguments holds all strings. 
} 

那麼,如何處理字符串參數的n個數?

+2

不確定「doctype」是否正確選擇單詞。 – 2010-08-28 10:45:51

+0

你的意思是如何在jsdoc中寫入這些參數? – 2ndkauboy 2010-08-28 10:49:50

+1

你是要求JavaScript還是PHP?你的代碼是JS,但你接受了PHP答案。如果它的PHP,請更改(或刪除)該示例,並刪除javascript和jsdoc標記。對於JS,在鏈接問題中已經有了一個答案(http://stackoverflow.com/questions/4729516/correct-way-to-document-open-ended-argument-functions-in-jsdoc)。 – studgeek 2011-05-03 18:00:05

回答

12

E.g. PhpDocumentor建議使用省略號

/** 
* Example of unlimited parameters. 
* Returns a formatted var_dump for debugging purposes 
* (since the recurrences of $v are not listed in the actual function signature in the code, 
* you may wish to highlight they are "optional" in their description) 
* @param string $s string to display 
* @param mixed $v variable to display with var_dump() 
* @param mixed $v,... unlimited OPTIONAL number of additional variables to display with var_dump() 
*/ 
function fancy_debug($s,$v) 
{
+3

打我吧。參考:http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.param.pkg.html – 2010-08-28 11:04:54

+0

這似乎不工作了,當使用phpDocumentor2 – ChrisF 2013-05-04 11:41:22

+1

什麼時候它是完全可變類似'function foo(){ $ args = func_get_args(); ''? – SeldomNeedy 2016-10-18 00:32:06

相關問題