Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of redundant php docblock tags like @static?

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).

like image 440
Matthieu Napoli Avatar asked Sep 09 '12 20:09

Matthieu Napoli


People also ask

What is static function in PHP and what advantage it brings in execution environment over normal function?

In certain cases, it is very handy to access methods and properties in terms of a class rather than an object. This can be done with the help of static keyword. Any method declared as static is accessible without the creation of an object.

Why do we use static in PHP?

The static keyword is used to declare properties and methods of a class as static. Static properties and methods can be used without creating an instance of the class. The static keyword is also used to declare variables in a function which keep their value after the function has ended.


1 Answers

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.

like image 176
BoltClock Avatar answered Oct 09 '22 00:10

BoltClock