17

好的,我的类方法上面确实有这个 phpdoc

/**
 * this a function that translates the text
 * @param string|boolean $lang if string the string given in the parameter will be the language code that will represent the language desired, if true, this will translate based on the website's current language, if false will not translate.
 */

现在我的问题是,我如何定义$lang只能接受字符串和布尔值的数据类型。

在我看到的其他文档中,mixed但它在我的带有 PDT 的 Eclipse IDE 中没有正确反映。

我的问题是我如何显示某个可能接受两种或多种数据类型的标准方法是什么。@param

注意:我给出的 phpdoc 是我现在正在工作的应用程序的现有文档。好吧,我被分配很好地记录一切。

4

1 回答 1

26

你做对了。PHPDoc 参考为可以是多种数据类型的参数提供了这两个选项(强调我的)。

数据类型应该是有效的 PHP 类型(int、string、bool 等)、对象类型的类名或简单的“混合”。此外,您可以通过用竖线分隔单个参数来列出多个数据类型 (例如“@param int|string $p1”)。

于 2012-07-26T05:50:38.590 回答