繁体   English   中英

我如何使用phpDoc指示php函数中的参数具有确定的类的类型?

[英]How can I indicate that a parameter in a php function has a type of determined class using the phpDoc?

在此示例中:

/**
 *
 * @param <type> $foo
 * @return <type> 
 */
function do_something($foo) {
    return $foo->really_do_something();
}

如何指示$ foo必须属于Foo类?

/**
 *
 * @param Foo $foo
 * @return <type> 
 */
function do_something(Foo $foo) {
    return $foo->really_do_something();
}

PHP的最新版本(我认为从PHP 5开始)具有参数类型:

function do_something(Foo $foo) {
   return $foo->really_do_something();
}

如果$ foo不是Foo类型,它将抛出异常。

我假设phpDoc接了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM