如何在 PHPDoc 中标记参数是可选的?
我有这个带有可选参数的构造函数。这样做的主要问题是可用性。使用我的框架的开发人员会立即感到头疼,因为他不知道他是否可以提供一个论点,什么样的论点,或者他是否根本不能。结论:这很糟糕。但是如果有人安装了像 Netbeans 这样的合理 IDE,PHPDoc 可能会有所帮助;)
那么:
class ChildClass extends ParentClass {
public function __construct() {
$tplFile = func_get_arg(0);
if (!isset($tpl)) {
$tpl = 'index';
}
parent::__construct($tpl);
}
}
我如何在这里使用 PHPDoc 来指示可以提供可选的 [$tpl] 参数?
I've got this constructor that takes an optional argument. The main problem with this is usability. The developer using my framework will catch a headache instantly because he doesn't know if he can provide an argument, what kind of argument, or if he can't at all. Conclusion: It just sucks. But PHPDoc may help a little bit if someone has a reasonable IDE like Netbeans installed ;)
So:
class ChildClass extends ParentClass {
public function __construct() {
$tplFile = func_get_arg(0);
if (!isset($tpl)) {
$tpl = 'index';
}
parent::__construct($tpl);
}
}
How could I use PHPDoc here to indicate that there can be provided an optional [$tpl] argument?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
声明一个参数并给它一个预设:
我的 IDE(phpEd,对 phpDoc 敏感)可以正确解释它。 phpDoc 也应该将参数放入大括号中:
Declare a parameter and give it a preset:
my IDE (phpEd, which is phpDoc sensitive) interprets it correctly. phpDoc should, too, and put the parameter into braces:
您也可以使用 反射类 来实现此目的。
You can use reflection class for this too.