文档:如何记录一个函数可以 return 多于一种类型的变量?
Documentation: how do I document that a function can return more than one type of variable?
假设一个 PHP 函数是这样的:
/**
* Description
*
* @return Namespace\GenericObject
*/
function doSomething() {
if ($some_parameter) {
return new GenericObject;
} else {
return FALSE;
}
}
如何使用 PHPDoc 标准记录函数的 return
?据我所知,一个函数应该只有一个 return
记录,但是,上面的函数可以 return 一个新对象或一个布尔值。
使用或 |
运算符。
/**
* Description
*
* @return Namespace\GenericObject|null|array|false
*/
function doSomething() {
if ($some_parameter) {
return new GenericObject;
} else {
return FALSE;
}
}
假设一个 PHP 函数是这样的:
/**
* Description
*
* @return Namespace\GenericObject
*/
function doSomething() {
if ($some_parameter) {
return new GenericObject;
} else {
return FALSE;
}
}
如何使用 PHPDoc 标准记录函数的 return
?据我所知,一个函数应该只有一个 return
记录,但是,上面的函数可以 return 一个新对象或一个布尔值。
使用或 |
运算符。
/**
* Description
*
* @return Namespace\GenericObject|null|array|false
*/
function doSomething() {
if ($some_parameter) {
return new GenericObject;
} else {
return FALSE;
}
}