Jetbrains Webide: PHP Variable Type Hinting

JetBrains WebIDE: PHP variable type hinting?

/* @var ClassName $object */ is a non-valid PHPDOC comment and is not parsed in the current version of Web IDE. Use double asterisks to make it work:

/** @var ClassName $object */

Also, you can annotate $array in foreach($array as $var) with /** @var ClassName[] $array */ and $var type will be deduced automatically.

How to specify the IDE Netbeans, that the PHP variable has a specific type?

With netbeans, you may document your variable with the following syntax :

/* @var $variable MyClass */
$variable = getSomething();

// netbeans will assume that your variable is the MyClass type and will provide code completion.

To auto-complete this string, you may use the following shortcut: type vdoc and press Tab key.

Source for this answer on the Oracles's netbeans php blog.

PHPDoc type hinting for array of objects?

Use:

/* @var $objs Test[] */
foreach ($objs as $obj) {
// Typehinting will occur after typing $obj->
}

when typehinting inline variables, and

class A {
/** @var Test[] */
private $items;
}

for class properties.

Previous answer from '09 when PHPDoc (and IDEs like Zend Studio and Netbeans) didn't have that option:

The best you can do is say,

foreach ($Objs as $Obj)
{
/* @var $Obj Test */
// You should be able to get hinting after the preceding line if you type $Obj->
}

I do that a lot in Zend Studio. Don't know about other editors, but it ought to work.



Related Topics



Leave a reply



Submit