annotating a local variable in php annotating a local variable in php php php

annotating a local variable in php


The Phpdoc standard does not cover these annotations (it only cover class properties with the @var tag); however, it is perfectly possible in Eclipse (e.g. PDT):

/* @var $variable Type */ ^         ^        `--- type |      variable            | `--- single star

This also works in all other PHP IDEs like Netbeans or Phpstorm which is useful if you exchange your code with others.

Example Code:

<?php/* @var $doc DOMDocument */$doc-> 

Example Screenshot (Eclipse PDT (Indigo)):

Eclipse PDT (Indigo)

Related Question & Answers:


This is an old question, but only for reference.You must include the Use statement for the Type in current file in order to @var annotation work

<?phpuse YourVendor\YourBundle\Entity\ProductType;.../* @var $product_type ProductType */$foo = $product_type->getName();