views:

27

answers:

3

I'm trying to get NetBeans 6.8 code completion to work for this. It doesn't seem to do it by itself, but I'm wondering if there's some phpdoc magic or something that may help, since it seems pretty darn good at using that.

Take the following two classes:

class A {

    public $B;
    public function __construct() {
        $this->B = new D();
    }
    public function C() {
        echo "C";
    }

}

class D {

    public $E;
    public function __construct() {
        // Do stuff.
    }
    public function F() {
        echo "F";
    }

}

Now, let's say I do $A = new A(); and then start typing $A->B->

Assuming that both classes are defined in the same file, this works perfectly. I get code complete suggestions for the E variable and the F method.

However, if the classes are split up into A.php and D.php respectively, and included into another file (say, index.php), doing the same thing after including both files gives only No Suggestions.

Any ideas? Thanks in advance!

+1  A: 

I think netbeans doesn't look at the actual includes you do, but rather at the project's include path. Set that, and it should work. The reason probably has to do with the fact that most people use autoloading anyway, and following that would be a bit too much to ask.

tdammers
+2  A: 

It works for me in most cases, but if you have problems use /* @var $variable ClassName */ before line with $A = new A()

You can use a shortcut for this: type vdoc and press tab.

Mchl
A: 

To extend upon Mchl's anwser:

If both files are in your project, and you use correct doc-blocks, code completion will find what you're looking for. To give an example:

/**
 * Class A
 * 
 * @author Yourname <And@Email>
 * @package Example
 */
class A {

    /**
     * @var D
     */
    public $B;

    /**
     * Constructor
     */
    public function __construct() {
        $this->B = new D();
    }

    /**
     * Function C
     * 
     * @return string
     */
    public function C () {
        return "C";
     }

}

Typing the /** and hitting enter right before a method or variable will trigger the creation of such a block, provided it has been written already...

Sjon