我有这个代码:
/**
* Days to parse
* @var int
*/
const DAYS_TO_PARSE = 10;
...
Run Code Online (Sandbox Code Playgroud)
我不认为使用@var对于常量是正确的,我没有看到任何@constantPHPDoc标记.这样做的正确方法是什么?
什么是记录其值预期为预定义常量的函数或方法参数的推荐方法?到目前为止,我使用常量的数据类型,稍后我会添加一些解释.
例如:
<?php
class Foo{
const METHOD_GET = 'get';
const METHOD_POST = 'post';
/**
* Load a new foo
*
* @param string $method HTTP method to use (either Foo::METHOD_GET or Foo::METHOD_POST)
*/
public function load($method=Foo::METHOD_POST){
// ...
}
/**
* Sort current foo
*
* @param int $sort_order Sort order (either SORT_ASC or SORT_DESC)
*/
public function sort($sort_order=SORT_ASC){
// ...
}
}
Run Code Online (Sandbox Code Playgroud)