Question

I know trying to do OOP in PHP is just silly, but here goes nothing:

In NetBeans, I can type these "vdoc" comments to give NetBeans' autocomplete a little push in the back

/* @var $parameters array */
$parameters;

But the same doesn't seem to work for class properties

class Foo {    
    /* @var $parameters array */
    private $parameters;

    public function __construct(array $parameters) {
        $this->parameters = $parameters;
    }
}

If I start adding methods to Foo that use the $parameters property, NetBeans' autocomplete shows that $parameters is of type ?.

Autocomplete

--

Is type hinting for class properties at all possible, perhaps using a different syntax?

Was it helpful?

Solution

I figured it out. The answer was actually pretty damn obvious. (blush)

The correct syntax is the same as for any PHPDoc:

/**
 * @var array 
 */
private $parameters;

I'm surprised nobody managed to point this out in the 5 hours between me asking this question and me discovering the answer myself. Oh well.

OTHER TIPS

It may go in front of the class declaration too, like this

/**
 * @property string $firstName
 * @property string $lastName
 */

class MyClassNmae
{
   ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top