0

I do know several posts exists on Netbeans and autocompletion, but none seems to give me the answer to the basic problem i'm facing:

if i do so:

use Project\Foo;
$foo = new Foo;
$foo-> //autocompletes properly all the methods

but if do so:

use Project\Foo;
use Project\Bar;

$foo = $bar->getSomeObject();
$foo-> //doesn't show anything

I've been used to Visual Studio and VB .NET where the keyword AS simplifies the IDE to know which type to autocomplete

How can i explicitly inform Netebans autocompletion i'm manipulating a specific class ?

Any help or link to the same related topic would be much appreciated.

Pierre Roudaut
  • 1,013
  • 1
  • 18
  • 32
  • Does `Project\Bar::getSomeFoo()` has an `@return Project\Foo` typehint in it's docblock (compare: http://stackoverflow.com/q/9751766/367456)? If not, see as well http://stackoverflow.com/questions/390192/autocomplete-for-php-objects-with-classes-in-pdt-netbeans?rq=1 – hakre Apr 20 '14 at 11:38
  • I specified @return in it's docblock but to be more specific with my problem, i should have called the function Project\Bar::getSomeObject() since it returns a generic object. – Pierre Roudaut Apr 20 '14 at 11:44
  • 1
    What is the generic object? An interface? Any object? Then you might need to var-hint it for `$foo` only, see the second link, it is also outlined here on this Netbeans site: https://blogs.oracle.com/netbeansphp/entry/defining_variable_type_in_a - I think that `@var` notation comes close to the AS in VB.net (or VB classic even). – hakre Apr 20 '14 at 11:45
  • What i called a generic object was simply an custom object. The var-hint solve what i was looking for, thank you for your help! – Pierre Roudaut Apr 20 '14 at 11:53
  • Alright & fine. I closed now against an `@var` suggesting duplicate question. That will link your question with those answers. – hakre Apr 20 '14 at 11:57

1 Answers1

0

You need to make sure of two things to get hinting to work

class Bar {
    /**
     * @return \Foo
     */
    function getSomeObject() {
        return new \Foo();
     }
}
  1. Set up your code in a project. This lets Netbeans know where your code can be found
  2. Document your code with phpdoc comments. This way, Netbeans has a clear path to follow (in your example, does getSomeObject have an @return declaration?). Netbeans makes this easy. Just type /**<enter> and Netbeans will make the block for you and autocomplete the block as you type
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • I specified @return in it's docblock but to be more specific with my problem, i should have called the function Project\Bar::getSomeObject() since it returns a generic object. The var-hint solve what i was looking for anyway, but thanks for helping. – Pierre Roudaut Apr 20 '14 at 12:38