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).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With