How to get intellisense for PHP associative array index? [duplicate]

只愿长相守 提交于 2019-12-01 17:20:02

问题


Possible Duplicate:
PHPDoc for variable-length arrays of arguments

Whenever I type $_SERVER[''] and hit Ctrl + Space it gives me the list of possible indexes. How can I make it possible to array's I've created?


回答1:


The code completion for $_SERVER gives you hints on the typical values people get out of that associative array. It is hard-coded somewhere in the NetBeans source code. For an arbitrary array, NetBeans has no idea of the keys that are used in any array, and thus does not provide hints there. It is even possible to proof that it is impossible to reliably implement such a feature, so I think you are out of luck here.




回答2:


If you use variables as a objects, you can make a fake empty class with properties and phpDOC for each property, declare the object of that class, and netbeans will autocomplete the properties (keys of the object).

 <?php
  namespace Models\Geo;
 /**
 * Results from GeoNames.
 * Dummy class for autocompletition only
 * See http://trac/wiki/Geo
 * 
 * @property string $countryName
 * @property string $adminCode1
 *  ...
 * @property string $population
 * 
 * @category BNT
 * @package Library
 */
class GeoNamesResult
{
}
?>

Then in your netbeans code

<?php
/* @var $obj \Models\Geo\GeoNamesResult */
$obj->   // will autocomplete with countryName, adminCode1 etc...
?>

Of course if a function is returning $obj and it has the phpDoc @return, there is no need to use the comment @var




回答3:


You can't but the best you can do is to use phpDocumentor to document your code.



来源:https://stackoverflow.com/questions/6358007/how-to-get-intellisense-for-php-associative-array-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!