How to declare the type for local variables using PHPDoc notation?

Both answers are wrong*, strictly speaking:

/** @var MyJobObject $job */

Is correct - the type is always the first argument, then you put a description or specify the variable itselfs.

Resources:

https://scrutinizer-ci.com/docs/tools/php/php-analyzer/guides/annotating_code https://docs.phpdoc.org/latest/references/phpdoc/types.html

Otherweise, every modern PHP IDE is able to recognize almost any kind of comment syntax:

// @var
/* @var */
/** @var */
/* @var
*/
# @var

The most common, most readable and most widely accepted form is

/** @var <type> [variable [comment]] */


/** 
 * @var <type> [variable [comment]] 
 */

PSR-5 (Proposed) https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md

PSR-19 (Draft) https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md

*) In 2013 the syntax might have been different.


You have to use the one-line form: /** @var $job MyJobObject */

Note that some editors prefer the syntax the other way around: /** @var MyJobObject $job */


You shoud do on top of your view / template file.

<?PHP
/* @var $job MyJobObject */
?>