views:

73

answers:

2

Hello! Whenever I need to use the intelligence of Netbeans to show properties/methods, I explicitly declare a new object and then re-reference it. Something like..

    $moo = new Cow();
    $moo = Cow::getById(1);
    $hasMilk = $moo->hasMilk();

Is there a way I can avoid this by type-casting the variable when getting it? Or atleast a hack to fool Netbeans?

Thanks!

PS: the main reason of solving this is something if I forget to comment line 1, and when obj is not found, it works with a fresh object! :(

+1  A: 

Type vdoc and press tab. In the comment that appears put name of the class.

Mchl
Thanks Mchl for the Shortcut. What is the shortcut to bring out the template for a method?
Prasad
Tools -> Options -> Editor -> Code templatesThere you can review existing and add your own templates.
Mchl
+3  A: 
$moo = Cow::getById(1); /* @var $moo Cow */

this will tell netbeans that $moo is an object of type Cow

Maerlyn
I use this a lot. Note that `/**` doesn't work. Silly, but true.
Coronatus
@Coronatus Indeed, I found that quite strange, part because `/**` marks the beginning of a docblock, part because my previous editor (phped) used that.
Maerlyn
Prasad
Or you can add a DocBlock to the method getById() on Cow with @return stating the type, and Netbeans will know when you use getById() that $moo is a Cow.
Stephen Melrose