简体   繁体   中英

member variables and @var phpdoc type hinting

I've been using inline @var declarations for type hinting PHP to use the prediction and reference jumping in Eclipse but what is the structure when it is a member variable like in the example below? (the below does not seem to work)

/* @var $this->obj AbcObj */
$this->obj = Factory::get(...);

*Assume a wide variety of object types can come out of the factory.

In the class declaration that $this represents, if you have declared $obj as a class variable, then put a docblock on it:

class Foo
{
    /**
     * @var AbcObj
     */
    $obj = null;
}

That should give you exactly what you're after. That inline /** @var thing was something that evolved out in the wild to give this behavior to local non-class variables, based on wanting that autocompletion that exists for class variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM