RusAlex
RusAlex

Reputation: 8575

phpdoc @var in php file

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.

Upvotes: 3

Views: 2226

Answers (3)

Tschallacka
Tschallacka

Reputation: 28722

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;
    }
}

Upvotes: 0

Alsciende
Alsciende

Reputation: 26971

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->

Upvotes: 0

Alfwed
Alfwed

Reputation: 3282

The following syntax works fine in eclipse

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

Note that I switched parameters order.

Upvotes: 4

Related Questions