Quantcast
Channel: PHPDoc type hinting overlapping types - Stack Overflow
Viewing all articles
Browse latest Browse all 2

PHPDoc type hinting overlapping types

$
0
0

I have a class called Resource but with a fully qualified name like com.example/objects/Resource

If I write a file

use com.example/objects/Resource;/** * Do something *  * @param Resource $r  */function myfunc( Resource $r ) {    $r->something();}$x = new Resource();myfunc($x);

Then everything works fine. Because of my use statement, the PHP typehinting is able to handle the the fact that I've passed a variable of type com.example/objects/Resource even though myfunc is only comparing against Resource

The problem is that PHPStorm is not able to handle this. I'm unable to use autocomplete and I get a warning on myfunc($x) which says Expected Resource, got Resource and a warning within the function which says Method 'something' not found in the class Resource. Obviously PHPStorm is assuming I'm using the builtin resource class and not my own Resource class.

If I change the PHPDoc and the function definition to use the fully qualified name, then the previous warnings go away but I get a minor warning which says Unnecessary fully qualified name. I suppose one solution would be to use the fully qualified name and disable the minor warning, but I'd rather not have to use fully qualified names everywhere. I know it's my own fault for creating a class which has the same name as a built in type, but I'm wondering if there is anyway to make this work? Apart from renaming my Resource class?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images