Sunday, 15 July 2012

php - In PHPStorm, how can I make type hinting work when I have a superclass method that returns a different type from each subclass -



php - In PHPStorm, how can I make type hinting work when I have a superclass method that returns a different type from each subclass -

i have class inheriting superclass , superclass has static find() method instantiates instances of subclass (active record pattern).

class activerecordclass { /** * @return mixed */ public static function find() { // code returns instance of called class } } class modelclass extends activerecordclass { } // returns instance of modelclass, phpstorm doesn't realise modelclass::find($model_id);

at moment, docblock not much code completion , type hinting. can't utilize superclass homecoming type subclasses have different methods due db columns.

how can indicate phpstorm superclass find() method returns instance of subclass it's called from, code completion works?

found it:

class activerecordclass { /** * @return static */ public static function find() { // code returns instance of called class } }

it seems @return self vs @return static works same way expect given keywords do. @return self did not pick methods available on concrete subclass, @return static create autocomplete work great.

php phpstorm

No comments:

Post a Comment