PHPdoc@param中的两个或多个数据类型


two or more datatypes in PHPdoc @param

好的,我的类方法的上面有这个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的数据类型,它可以同时接受字符串和布尔值ONLY。

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

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

注意:我给出的phpdoc是我现在工作的应用程序的现有文档。好吧,我被指派把一切都记录好。

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

数据类型应该是有效的PHP类型(int、string、bool等)对象类型的类名,或者简单地"mixed"。此外,您可以为单个参数列出多个数据类型,方法是用管道(例如"@param int|string$p1")