Netbeans/Eclipse/Zend @var annotations (not to be confused with docblocks1) are a mechanism to declare variable types explicitly:
/* @var $db Database */
$db->prepare($sql);
It's a tool to provide hints for code intelligence and it comes in handy to overcome the limitations of static analysis, either when the engine is not powerful enough or in edge cases when static analysis is just not possible (variables in views defined elsewhere, dynamically generated code, undocumented third-party libraries...). As far as I know it's supported by a number of major IDEs including NetBeans and PhpStorm.
(1) Differences:
phpdoc block comments start with /** and are placed right before the item _definition_:
/**
* @var Database $db Database connection instance
*/
protected $db;
Variable type inline comments start with /* (thus won't show up if you generate actual documentation with phpdoc) and are placed somewhere before the item _use_:
$foo = $this->db;
/* @var $foo Database */
$foo->...
Also, the arguments are swapped, though PhpStorm accepts any order:
Supporting type hints in comments other that do not use /** syntax is out of scope as it would mean we cannot rely on phpDoc's parser anymore. It's also not in line with the PHP docblock PSR. I also don't see why you would want to document the reference and not the definition of the variable.
I'd be glad to elaborate on the use cases I highlighted but if it isn't really doable because parsing needs to be done with a docblock parser then the feature is probably not worth considering.
I added support for this in my fork: https://github.com/james2doyle/php-language-server/commit/0c56bffd4c0699751c3688b5a122ef3ada000ea0
It isn't super elegant but it does the job
@james2doyle Is there a way to install your fork and have a look at how it works?
Yeah it's the same as this one. Just swap out the package names
On Tue, Jul 3, 2018, 5:01 AM Ălvaro GonzĂĄlez, notifications@github.com
wrote:
@james2doyle https://github.com/james2doyle Is there a way to install
your fork and have a look at how it works?â
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/felixfbecker/php-language-server/issues/650#issuecomment-402130769,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABW_mOk69uwJLg1A0M6drIBwDCw0aK92ks5uC10ugaJpZM4UtfiQ
.
@james2doyle Sorry if I didn't explain myself correctly. Since forks are obviously not available in the usual channels (Visual Studio Marketplace, Packagist...) it isn't always obvious how to use them.
I've figured how to install it right from GitHub:
{
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/james2doyle/php-language-server"
}
],
"require": {
"felixfbecker/language-server": "dev-master"
}
}
I'll see if I can plug it into my editor.
@james2doyle Got it. I just had to replace %USERPROFILE%\.vscode\extensions\felixfbecker.php-intellisense-2.3.3\vendor with yours. It also doesn't seem difficult to build the VSCode extension itself with Node but I haven't tried.
Now, perhaps I'm missing something but I can't make it work. I created a random class somewhere in the project and tried this:
<?php
function doStuff()
{
/* @var $foo FastBender */
global $foo;
$bar = new FastBender();
}
But Visual Studio Code still seems unaware of what $foo is and offers entirely different code intelligence for $foo and $bar:





It supports docblocks not single line declarations. Try that and see
On Tue, Jul 10, 2018, 1:38 AM Ălvaro GonzĂĄlez, notifications@github.com
wrote:
@james2doyle https://github.com/james2doyle Got it. I just had to
replace
%USERPROFILE%.vscode\extensions\felixfbecker.php-intellisense-2.3.3\vendor
with yours. It also doesn't seem difficult to build the VSCode extension
itself with Node but I haven't tried.Now, perhaps I'm missing something but I can't make it work. I created a
random class somewhere in the project and tried this:
function doStuff()
{
/* @var $foo FastBender */
global $foo;
$bar = new FastBender();
}But Visual Studio Code still seems unaware of what $foo is and offers
entirely different code intelligence for $foo and $bar:[image: $bar->]
https://camo.githubusercontent.com/dc1a600b2c8b8f43902edad5f16f8c271c6281f3/68747470733a2f2f692e696d6775722e636f6d2f59536e6a5163532e706e67[image: $bar->printFrobble(]
https://camo.githubusercontent.com/79d219e7b35127713c5115695b3493e9bb76fbcd/68747470733a2f2f692e696d6775722e636f6d2f4d5376794e6c6b2e706e67[image: $foo->]
https://camo.githubusercontent.com/680fe1e8079bb7391442fa6950d418c05d8eea6b/68747470733a2f2f692e696d6775722e636f6d2f757451653462332e706e67[image: $bar->printFrobble(]
https://camo.githubusercontent.com/b8c1e050bd487a1bdbf42361bcf0ffec6e62ac58/68747470733a2f2f692e696d6775722e636f6d2f673570735169612e706e67â
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/felixfbecker/php-language-server/issues/650#issuecomment-403745513,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABW_mLT686AqO6HMfzBfxHa9yyUvtYbvks5uFGgDgaJpZM4UtfiQ
.
I'm closing this ticket because, after some further research, I reached the conclusion that this annotation format is mostly dead. Tools that implement this kind of feature nowadays use the syntax proposed on the _PSR-5: PHPDoc_ draft:
/** @var \Database $db */
Most helpful comment
I'm closing this ticket because, after some further research, I reached the conclusion that this annotation format is mostly dead. Tools that implement this kind of feature nowadays use the syntax proposed on the _PSR-5: PHPDoc_ draft: