Tuesday, May 19, 2009

@var magic comment

This is a good example how people get used to a bad habits. @var magic comment has appeared first in early Zend Studio, and this is how it was used:



As you can see this magic comment makes content assist know what is the type of $test variable. With PDT 2.0 we have canceled this behaviour due to promising type inference engine, that can resolve variable back to the place where it was declared. For example:




As it turned out later this is not enough for most PHP developers as there are many cases where there's no reference from variable usage to its declaration (if declaration exists at all). One example has changed our mind, and we've decided to fix 260805, 249705 and 257481 ASAP.
One famous MVC framework magically allows to refer to View members from within .phtml script using $this variable. To support this you definitely need something to tell content assist that $this variable is actually an instance of some class even though it appears in a global scope...
Ouch... PHP is full of magic :)

PS: @var comment fixes are available in 2.1.0M7, but I suggest using latest integration build.

2 comments:

Anonymous said...

@var works well in NetBeans 6.5 (with PHP)

Matthew Weier O'Phinney said...

Just a quick note: While Zend_View does this, Zend_View is a sibling/ancestor of Savant 2/3 and Solar_View -- in other words, we're not the only code on the block doing this. :)