문제

When using automatic php docblock generation in PhpStorm, I ended up with the @static annotation on a static method:

/**
 * Reset the singleton instance, for the tests only
 * @static
 */
public static function reset() {
    self::$singletonInstance = null;
}

Is there any use for these tags if they can be inferred from the code? I'm trying to decide if I should leave it or remove it (and do so everywhere so it's consistent).

도움이 되었습니까?

해결책

These tags were introduced for legacy PHP 4 code that didn't permit the use of such keywords in code. With PHP 5, the code is effectively self-documenting, so these tags are indeed redundant; I don't see any reason to keep them around.

In fact, if you ever generate documentation for your PHP 5 source files, phpDocumentor should still be able to determine that these are static methods. This is mentioned in the phpDocumentor docs:

Just using the static keyword in your code is enough for PhpDocumentor on PHP5 to recognize static variables and methods, and PhpDocumentor will mark them as static.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top