Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php docBlock-将类型放入@param,是否导致异常?_Php_Coding Style - Fatal编程技术网

php docBlock-将类型放入@param,是否导致异常?

php docBlock-将类型放入@param,是否导致异常?,php,coding-style,Php,Coding Style,假设您得到以下方法: /** * @throws \Exception **/ function foo($param): void { if (!(is_string($param) | is_array($param))) { throw new \Exception('Param is neither string nor array!'); } postProcess($param); } 方法本身接受所有参数类型,但如果参数既不是字符串也不是

假设您得到以下方法:

/**
* @throws \Exception
**/
function foo($param): void
{
    if (!(is_string($param) | is_array($param))) {
        throw new \Exception('Param is neither string nor array!');
    }

    postProcess($param);
}
方法本身接受所有参数类型,但如果参数既不是字符串也不是数组,则抛出。 对于此方法,您更喜欢以下哪个
@param
-标记

  • @param mixed
  • @param string|array

  • 我假定它是基于意见的,但我会设置
    @param string | array
    ,以便更清楚地解释所支持的类型。您还可以添加注释(到
    @throws
    @params
    或两者),如:

    通常混合使用。
    /**
     * @throws \Exception If the provided argument is not array or string
     *
     * @param string|array $param Bla-bla-bla. If not array or string - \Exception will be thrown.
     */