Defining a variable type in comment
Yesterday was the first day at work this year and we committed new feature, which allow to define a type for a variable in a comment. The comment has to be defined in specific form as is displayed on the picture.

The comment has to be /* @var $variable type */ . If the comment is written in the right form, then the var tag has bold font.
You can use this helper, when NetBeans is not able to recognize the type of the variable. On the picture below you can see that NetBeans recognizes that the variable $media in the echo statement is Book type. But then another object is assigned to the $media variable through the getLastMovie() function. This function defines the return type Movie, so from this line NetBeans knows that $media variable contains an object of Movie type.

NetBeans handles the variable name and the type from the comment helper as are handled in PHP Doc. So for example mark occurrences works as usual.

Next time I will show you how NetBeans can help you with writing the comment helper.

Hello,
great new feature :-)
But I found a bug:
When I use this Code everything is OK:
/* @var $l_value Image */
foreach ( $imageList as $l_value )
{
$l_value->...
}
But with this Code, I get an Exception:
foreach ( $imageList as $l_value ) /* @var $l_value Image */
{
$l_value->...
}
Greetings,
Stefan Sturm
Posted by Stefan Sturm on January 06, 2009 at 10:58 AM CET #
To Stefan: thanks for finding this problem. I'm going to fix it today.
Posted by Petr on January 06, 2009 at 11:52 AM CET #
Good one. It was implemented first in Zend Studio 6 if I remember correctly. Helped me a lot when I was using ZSE.
Posted by Sam on January 06, 2009 at 12:39 PM CET #
Great feature, but how about arrays of object? How to make Netbeans to complete this?:
$a = array();
$a[] = new Movie();
$a[] = new Movie();
$a[0]-> [code competition here]
foreach ($a as $element) {
$element-> [code competition here]
}
Posted by Leszczu on January 06, 2009 at 12:39 PM CET #
The problem, which was mentioned by Stefan is now fixed.
Posted by Petr on January 06, 2009 at 07:49 PM CET #
Code completion doesn't seem to work in the following situation.
$something->anotherthing()->|
even tho I have PHPDoc'ed the function anotherthing to return a different object type, I still get the codecompletion of the something object.
Posted by Jacob on January 07, 2009 at 01:59 AM CET #
This is the most important feature I was waiting for.
Thanks a lot.
Posted by Omar on January 07, 2009 at 11:09 AM CET #
To Jacob: strange it works for me. At least what I tried:
<?php
class Issue {
public function getDescription() {
}
}
class Bug {
function getDefaultPriority() {
return 3;
}
/**
* @return Bug
*/
public static function getLastBug() {
}
/**
* @return Issue
*/
public function depends() {
}
}
/**
* @return Bug
*/
function getFirstBug() {
}
/* @var $something DOMAttr */
$something->appendChild();
$something = Bug::getLastBug();
$something->depends()->getDescription();
?>
Could you try this example? Let me know, whether it work for you. If yes, then we should investigate more, why it doesn't work in your case.
Thanks,
Petr
Posted by Petr on January 07, 2009 at 12:21 PM CET #
Regarding Leszczu's question.
It would be nice to support something like:
/**
* @var array[Bar]
*/
$foo = array(new Bar, new Bar);
Posted by Amenthes on January 07, 2009 at 10:46 PM CET #
This is the most important feature I was waiting for. Thanks a lot.
Now is Netbeans practically better than commercial Zend Studio!!!
I miss only Zend Toolbar feature. It's very practical for run debugger from any state of application. How I can in Netbeans log to web application, make same operation and then run debugger after form submit?
Posted by Tomas Prochazka on January 08, 2009 at 07:01 AM CET #
I'm not sure what I am doing wrong, but it is not working for me. I use lazy loading. Could that be it?
Posted by Keith Davis on January 08, 2009 at 07:53 PM CET #
Hi Keith,
it's not connected with lazy loading. Which build do you use?
Posted by Petr on January 08, 2009 at 09:47 PM CET #
Fantastic!! I have been waiting for this for so long.
Posted by jsd on January 09, 2009 at 02:40 AM CET #
Just wondering how you get the build in which this has been enabled? I'm using Netbeans 6.5 on Windows Vista.
Posted by planetthoughtful on January 09, 2009 at 07:41 AM CET #
to planetthoughtful: download development version here: http://bits.netbeans.org/download/trunk/nightly/latest/
Posted by gawan on January 09, 2009 at 10:00 AM CET #
Thanks for your effort - lack of this feature often makes me think of getting back to Eclipse.
Doesn't work for me with member vars though:
class a
{
function x() {}
}
class b
{
/* @var member a; */
var $var_of_type_a;
function x()
{
$this->var_of_type_a-> // No suggestions
}
}
Posted by infozone on January 10, 2009 at 05:29 PM CET #
Sorry for typo:
/* @var member a; */ should had been
/* @var var_of_type_a a */ of course.
Doesn't work anyway. For what it worth, tested with 200901091401 nightly build.
Posted by infozone on January 10, 2009 at 05:39 PM CET #
To infozone:
There is PHP doc definition for classfield:
http://manual.phpdoc.org/HTMLframesConverter/default/phpDocumentor/tutorial_tags.var.pkg.html
As you can see, it's used the @var field, but the form is:
/** @var type */
So for class fields use the PHP doc.
Regards,
Petr
Posted by Petr on January 10, 2009 at 11:39 PM CET #
Oh, ok :) Thanks Petr, you're indeed correct. Then, wouldn't it be too difficult to make vdoc distinct whether it is used on a class member or a standalone var and apply corresponding syntax automatically?
Or better yet, make auto documentor (or whatever you call it) work similarly? I mean, if you type:
/**<enter>
above class var declaration, it results in
/**
* @var <type>
*/
with cursor located on the right of <type> placeholder, so that you need to erase it manually to indicate a type - very inconvenient. Should it select the placeholder and allow to type in an appropriate type over it, it would be much better. Actually even just removal of the <type> placeholder would be good in this case - although this doesn't solve similar issue with methods params, where you are getting something like:
/**
*
* @param <type> $a
* @param <type> $b
*/
with cursor located after $b, and then cannot even select <type> with just double-click, as it selects only word "type" but not the angle braces around it, so they require additional typing to be deleted.
Thanks again for your effort.
Posted by infozone on January 11, 2009 at 07:32 PM CET #
Hi Petr, nice feature, but I found a bug. Try this example:
<?
/**
* @property string $title
* @property string $body
*/
class Blog {}
/**
* @property string $name of user
* @property Blog $blog
*/
class User {}
/* @var $user User */
$user->blog->
?>
and after CTRL + SPACE netbeans offers me property of User not of Blog. I already added it into issuezilla: http://www.netbeans.org/issues/show_bug.cgi?id=156614
Little enhancement: Could you add text after @property into PHPDoc popup window (e.g. for property $name -> "$name of user") ?
Posted by gawan on January 12, 2009 at 02:54 PM CET #
To infozone:
I will think about your suggestion. You are right, that the current approach is not consistent.
To gowan:
Thanks for entering the issue. I have put a comment there.
Posted by Petr on January 13, 2009 at 01:32 AM CET #
Great!
The PHP plugin for netbeans improves every day helping our work!
Thanks!
Posted by Joao Neto on February 25, 2009 at 03:13 PM CET #
This is a fantastic addition. I'm so close to leaving Eclipse PDT behind.
I am having one problem though.
See example
abstract class SimpleObject {
public function methodOne() {
}
public function methodTwo() {
}
}
class ComplexObject extends SimpleObject {
public function methodThree() {
}
}
class Foo {
/**
* @var SimpleObject
*/
private $_object;
public function __construct(SimpleObject $example) {
$this->_object = $example;
}
/**
* Example method returns somthing like SimpleObject
*
* @return SimpleObject
*/
public function getOject() {
return $this->_object;
}
}
$foo = new Foo();
$fooObject = $foo->getOject();
/* @var $fooObject ComplexObject */
$fooObject->
Here I would want the vardoc to change what the editor thinks it has in $fooObject. Because I know what the object type is.
Posted by James Dempster on March 08, 2009 at 11:21 PM CET #
Hi - I have a problem not far from the problem Jacob statet. I have problems "type-casting" $this - and return value of methods are not properly working (when using an object "type-cast" via comments)
<?php
class Issue {
public function getDescription() {
}
/**
*
* @return Bug
*/
public function getLastBug() {
}
}
class Bug {
function getDefaultPriority() {
return 3;
}
/**
* @return Issue
*/
public function depends() {
}
}
/* @var $this Issue */
//$this resolves to "Bug" (Error)
$this->depends();
/* @var $bug Bug */
//$bug resolves to Bug - All ok...
$bug->depends();
/* @var $issue Issue */
//Return value of getLastBug resolves to Issue (Error)
$issue->getLastBug()->getLastBug()->getLastBug();
//Here everything is working:
$issue2 = new Issue();
$issue2->getLastBug()->depends();
I use $this "type-casting" alot since i use a Zend Framework approach to MVC. so a fix for this would be great! (Netbeans reacts so much faster than Zend Studio - speeding up production a lot!)
Im using the Netbeans 6.7 Beta (Just downloaded yesterday)
Posted by Henrik on May 18, 2009 at 09:59 AM CEST #
The Solaris 10 03/05 Certified software consists of the Solaris 10 03/05 Operating Environment and a subset of Solaris 10 patches which have been reviewed to ensure that their application introduces no new security vulnerabilities.
http://www.watchrolexshop.com
http://www.gamegoldme.com
http://www.cheap-lotrogold.com
http://www.globalsale.me/Aion-gold-083.aspx
http://www.cheap-gamegold.org
http://www.gamegoldvip.org
Posted by aion gold on June 25, 2009 at 07:31 AM CEST #
Hi
Really appreciate this feature but I think this feature is built keeping PHP as structured language.
My code is
function _initViewHelpers(){
$view = $this->_layout->getView();
}
where getView is a ZendFramework and returns Zend_View_Interface, but IDE shows ? for object $view after that line of code.
My work around which I hate to do is
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
/**
*
* @var Zend_View_Interface
*/
protected $_view;
function _initViewHelpers()
{
$this->_view = $this->_layout->getView();
}
}
As this you can see i have to put $this on every line.
Posted by Ali on July 04, 2009 at 05:14 PM CEST #
plastic card holders
plastic card holders are leaders and innovators in the plastic card holders industry catering for all your membership cards and any custom size plastic card holders required from small to big quantity. We are a one-stop center for your entire plastic card holders requirement. <a href="http://www.7days-printing.com ">plastic card holders</a>.Have your cards ready in less than 1 hour if necessary in high laminated plastic card holders quality without compromising on quality and durability! The plastic card holders will be highly glossy laminated, very falt, non peeling and very sharp!
[URL=http://www.7days-printing.com]plastic card holders[/URL].We are also the authorized distributor for all range of plastic card holders as well as javelin plastic card holders in malaysia for personalizing the plastic card holders with thermal printing of text and barcode as well as encoding the magnetic stripe and plastic card holders.
Posted by molly on July 27, 2009 at 06:58 AM CEST #
plastic gift card
As a leading company in the plastic gift card printing industry, our factory has paseed many certificate and produces over two million plastic gift card per year. Our plastic gift card is exactly like the credit cards.
<a href="http://www.7days-plasticcards.co.uk">plastic gift card</a> We produce plastic gift card. our plastic gift card is four color litho printed with heidilberg machines. If you order our plastic gift card, we will offer you the best value for your money without any waste. [URL=http://www.7days-plasticcards.co.uk]plastic gift card[/URL] Ordering plastic gift card from us directly over the phone or internet, we can give you the best price which you can not find elsewhere!Today, plastic gift card is various and the company supplies more than 5oo million plastic gift card annually to customers all over the world. But our plastic gift card has many advantages.
plastic card supplier
As a corporate has plastic card supplier facility manager or security professinal, you meet hundreds of plastic card supplier every day. It’s your job to identify plastic card supplier, but can you be expected to recognize every plastic card supplier in your facility? You’re going to need a little help from identification plastic card supplier, so take your pick: use standard size plastic card supplier like you’ll find at [URL=http://www.7daysprinting.com]plastic card supplier [/URL] or oversized photo ID badges like you’ll find at <a href="http://www.7daysprinting.com"> plastic card supplier </a >to verify identities. Use proximity or plastic card supplier to grant access to unattended building entries and bar codes or magnetic stripe plastic card supplier for accurate time and attendance tracking and more. Fargo systems integrators like us offer complete plastic card supplier personalization systems to help solve these challenges.
Posted by mary on July 27, 2009 at 06:59 AM CEST #
hologram maker
hologram maker is the most fundamental marketing tool that you always have with you. hologram maker contains business information about you and your company. hologram maker communicate the primary information of your company to your prospective customers- in a compact and simple way. hologram maker is a proven method which effectively advertises your business. Whether you are launching a new product or marketing an existing one, a hologram maker will always help you do it right.
[URL=http://www.hologram-sticker.co.uk]hologram maker[/URL]
hologram maker is used for presentation of your marketing materials in a superior way. hologram maker ontains multiple pockets inside to hold your marketing materials. By utilizing folders, you can enhance the presentation of your hologram maker. <a href="http://www.hologram-sticker.co.uk">hologram maker</a> hologram maker is a significant part of any company’s distinctiveness to others.
plastic card design
We can supply from stock a complete range of plastic card design for use with card printers. <a href="http://www.dynamicworldwide.co.uk">plastic card design </a>.The recently updated plastic card design fooers all the features required to create and design card layouts with ease of set up and simplified operation. Four editons of plastic card design are available from the entry level plastic card design which allows for connection to external databases and the encoding of contactless plastic card design.
[URL=http://www.dynamicworldwide.co.uk]plastic card design[/URL]Whatever your requirement, plastic card design has the solution. A plastic card design personalisation bureau service is offered, where pre-printed or plastic card design can be thermally printed, embossed and encoded to your specific requirements. plastic card design can also be produced by digital or litho print methods. Other brands of plastic card design can also be supplied and supported.
Posted by molly on July 27, 2009 at 06:59 AM CEST #
metal business card
Businesses of all sizes rely on a powerful but tiy tool to communicate their business information: the metal business card. <a href="http://www.metal-card.co.uk"> metal business card </a>Whether you’re a business behemoth or one-man-brand consultant, the appropriate metal business card is a must. metal business card printing can be a daunting task because metal business card come in all shapes and sizes. There are your standard dorizontal facing metal business card, and even metal business card with the rounded deges. That depends on what exactly you are trying to communicate with your metal business card.The appropriate content is very important for your metal business card selection. [URL=http://www.metal-card.co.uk]metal business card[/URL]Your customers should be able to easily remember what it is you offer and also be able to contact you from the information on your metal business card. The last thing you want to do is hand a potential customer a brilliantly designed metal business card that does not help them find you when they need you. metal business card printing goes beyong metal business card design.
printing gift card
printing gift card is the key to promoting your business. printing gift card also increase the number of new customers coming in to redeem their gifts. printing gift card offers bring in customers seeking discounts on new purchases. As one of the leading manufacturers of printing gift card. <a href="http://www.printing-gift.co.uk">printing gift card</a>Our company has supplied printing gift card for top retall companies. Generating new printing gift card is a big benefit to a successful printing gift card. Not only will your existing customers find printing gift card appealing, they will in turn tell other new potential customers about printing gift card. Branding on your new printing gift card raise awareness.[URL=http://www.printing-gift.co.uk]printing gift card[/URL] There are many advertising and branding opportunities with printing gift card. This is because of the many diverse things printing gift card can be used for today. printing gift card for business has been increasing in popularity for several years. We offer affordable custom printing gift card at the lowest prices around.
smart card security
Since our smart card security is produced with unique equipment, you can be sure that your smart card security will be of high quality. In addition, our smart card security options are fully customizable to meet any specific needs. Your smart card security can also be ordered in combination with the convenient key smart card security, which is a smaller version of your smart card security that can be easily attached to a key chain. [URL=http://www.smartcard-supplier.co.uk]smart card security[/URL]Our smart card security helps companies that need a new design creat smart card security. For companies that already have a smart card security, we can print directly from your own supplied smart card security artwork.
<a href="http://www.smartcard-supplier.co.uk"> smart card security</a>
All of our custom printed smart card security offer high resolution graphics. We offer options for smart card security production such as unique smart card security textures or transparent smart card security for or a highly appealing visual appearance.Your customers will truly see your new smart card security as an outstanding them or high value.
Posted by mollly on July 27, 2009 at 06:59 AM CEST #
Just wondering how you get the build in which this has been enabled? I'm using Netbeans 6.5 on Windows Vista.....
Thanks for sharing
Posted by medyum on August 20, 2009 at 04:51 PM CEST #
It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.
Posted by links of london on October 30, 2009 at 03:09 AM CET #