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
Expose "Use" Classes to Included File
How to Show an Alert Box in PHP
Wordwrap/Cut Text in HTML String
How to Implement Single Sign-On (Sso) Using Microsoft Ad for an Internal PHP App
How to Post Soap Request from PHP
Quickest Way to Read First Line from File
PHP Get Actual Maximum Upload Size
Transpose a PHP Multidimensional Array with Predefined Keys
Header("Location") Causes [500] Internal Server Error
What Is Difference Between PHP Cli and PHP Cgi
Can't Find the File Created by Outfile in MySQL
How to Give Apache Permission to Write to Home Directory
Ascii Library for Creating "Pretty" Directory Trees