What is the correct way to annotate (in PHPDoc) functions implemented via __callStatic
? More important: is there a way that will make NetBeans and PHPStorm understand that these are static methods?
If you want the bigger picture, here's how I got to this question.
Problem: In my current project we have a ton of classes that should really be singletons (DB proxies and the like). Needless to say, we have at least a few hundred require_once
and $foo = new FooProxy();
lines.
Solution: I created a Loader
class to solve this, using the __callStatic
magic method so we can just say $foo = Loader::FooProxy();
. It's perfect for our purposes, but:
Problem: This way there's obviously no type hinting in either IDE used in the team.
Solution: Every module defines a subclass of Loader
, adding methods that just route to __callStatic
.
Problem: Adding actually interpreted code just for auto-completion's sake is not acceptable (this could be argued, but let's accept it for the time being).
Solution: Let's not add any real methods, only declare the methods in PHPDoc like this:
<?php
/**
* @method FooProxy FooProxy()
*/
class BarLoader extends Loader {}
?>
Problem: FooProxy
is not a static method. None of the following make it static either:
<?php
/**
* @static
* @method FooProxy FooProxy()
*/
///////////////
/**
* @static @method A A()
* @method static A A()
* @method A static A()
* @method A A() static
*/
Making the class abstract makes no difference. About an hour of Google'ing turned up no solutions. The primary goal is to make the IDEs aware of these functions; having correct PHPDoc is not really a necessity.
Well, PhpStorm 3.0 will accept
@method static type name() description
See relevant feature request http://youtrack.jetbrains.net/issue/WI-4051
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