3

i have next php code

<?php
class A {
    public function foo() {

    }
}
/**
 * @var A $a
 */
$a->

I want to make my ide autocomplete $a-> correct, and show me that there is only one available method foo in $a. There is no any string like $a = new A(); $a instantiated in another place and handled by autoloader.

7
  • this probably depends highly on which IDE you're using. Commented Oct 11, 2011 at 7:43
  • it should depend on phpdoc. if phpdoc support it it should work in every ide, which uses phpdoc Commented Oct 11, 2011 at 7:45
  • @Rus I don't think this will work. What might have a chance to work is to get phpDoc to include the autoloader file first - that is possible in many IDEs but I have no idea whether it's possible in phpDoc itself Commented Oct 11, 2011 at 7:49
  • @Pekka, IDE can't calculate a runtime workflow of autoloader. it must be based on static phpdoc syntax. Commented Oct 11, 2011 at 7:52
  • @Rus many IDEs allow the addition of include files to parse for the purpose of documentation. You might be able to go that way Commented Oct 11, 2011 at 7:57

3 Answers 3

4

The following syntax works fine in eclipse

/* @var $a A */
$a->

Note that I switched parameters order.

Sign up to request clarification or add additional context in comments.

3 Comments

i see, which version of eclipse do you use ? in my eclipse Version: 3.7.0 Build id: I20110613-1736 it doesn't work.
I've just edited my answer. This syntax should works. I've tested it in eclipse helios 3.6.
note the whitespaces at begging and end are important for eclipse
0

For some reason PDT in Eclipse swaps the order of the @var parameters. This syntax works:

<?php
class A {
    public function foo() {

    }
}
/**
 * @var $a A
 */
$a->

Comments

0

I'm using a variant of eloquent that autopopulates variables and the autohinting utterly fails in my eclipse, wether I place it above, under it, single line, multi line comments.

I did find a way in which it does work for me.

class Foo extends Model {
    public function beforeSave() {
        $bar = $this->bar;
        foreach($bar as $baz) {
            $baz-> // <-- this works now \o/
        }
    }
    /**
     * @return \Foo\Baz\Models\Bar
     */
    public function getBar() {
        return $this->bar;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.