简体   繁体   English

当我使用PHP数组时,为什么Zend Studio无法在对象上显示自动完成菜单?

[英]Why does Zend Studio fail to bring up auto-complete menu on objects, when I use PHP arrays?

I seem to be having some trouble with my IDE or maybe my code. 我的IDE或代码似乎有些麻烦。 My IDE (ZendStudio 11 built on Eclipse) is not giving me auto-suggest methods on object when I put that object into a PHP native array construct. 当我将对象放入PHP本机数组构造中时,我的IDE(基于Eclipse构建的ZendStudio 11)没有为我提供对象的自动建议方法。

As you will see below, auto-suggest work for things that do not have $this-> (object accessor) and do not have [$index] (array accessor), but fail to work after those accessors are present. 如下所示,对于没有$this-> (对象访问器)和没有[$index] (数组访问器)但在存在这些访问器后无法工作的事物,自动建议工作。

Consider the Code below 考虑下面的代码

See comments for trouble areas 查看有问题区域的评论

namespace Name\Space;

class PointArrayManager
{

    private $points;

    public function __construct()
    {
        $point = new Point();
        $point-> //brings up auto-complete for Point()

        $points[0] = new Point();
        $points[0]-> //brings up auto-complete for Point()

        $this->points[0] = new Point();
        $this->points[0]-> //FAILS to bring up auto-complete 
    }
}

What causes this issue and can I improve my code to have autosuggest anyway? 是什么导致此问题,我是否可以改善代码以自动进行建议?

Your IDE has no way of knowing that your $points property is an array of Point objects. 您的IDE无法知道$points属性是Point对象的数组。 You will have to give it some help. 您将不得不提供一些帮助。

The way to do this is to comment your code, at the very least you will need to comment the declaration of the $points variable like this:- 这样做的方法是注释您的代码,至少您将需要注释$points变量的声明,如下所示:-

/** @var Point[] $points */
private $points;

I don't use Zend Studio, but this works in PHPStorm, so I imagine it does in Zend Studio too. 我不使用Zend Studio,但是它可以在PHPStorm中使用,因此我想它也可以在Zend Studio中使用。

Commenting your code like this is good practice and helps your IDE to know what you mean. 这样注释代码是一种很好的做法,可以帮助您的IDE理解您的意思。 It also helps with generation documentation. 它还有助于生成文档。 Most PHP IDE's use PHPDocumentor for comments, so the manual there is worth a read. 大多数PHP IDE都使用PHPDocumentor进行注释,因此该手册值得一读。

http://www.phpdoc.org/ http://www.phpdoc.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM