【问题标题】:NetBeans 8.1 (on Mac OS) PHP Autocompletion with $this->var does not workNetBeans 8.1(在 Mac OS 上)使用 $this->var 的 PHP 自动完成功能不起作用
【发布时间】:2016-03-01 22:58:38
【问题描述】:

奇怪的自动完成行为:

class myFirstClass
{
  public function myFunc1() {}
  public function myFunc2() {}
}

class mySecondClass
{
  /**
   * @return myFirstClass
   */
  public function getMyFirstClass()
  {
    return new myFirstClass();
  }

  public function init()
  {
    $myFirstClass = new myFirstClass();
    $myFirstClass-> // autoComplete works here and shows myFunc1 and myFunc2

    $this->myFirstClass = new myFirstClass();
    $this->myFirstClass-> // autoComplete does not work here

    $this->getMyFirstClass()-> // autoComplete works here and shows myFunc1 and myFunc2 

    $this->myFirstClass2 = $this->getMyFirstClass();
    $this->myFirstClass2-> // autoComplete does not work here

    $this->myFirstClass2->myFunc1(); // cmd+click on myFunc1() in this line jumps to the myFunc1-function in myFirstClass, so netbeans "knows" the right class, but doesn't autocomplete :(
  }
}

如果没有 $this,代码自动完成功能会按预期工作,但如果使用 $this->,它将不再显示任何内容。这是一个已知的 NetBeans 错误还是有解决此问题的设置?

【问题讨论】:

    标签: php netbeans autocomplete


    【解决方案1】:

    我猜 NetBeans 只对 $this->.... 有自动补全功能,对 $this->....->.... 没有自动补全功能,因此它不支持第一个箭头之后的任何内容。你是对的,它不起作用,因为它不打算这样做。

    问候。

    【讨论】:

    • 谢谢,但这似乎不是问题所在。我添加了一个带有两个箭头的工作示例。
    【解决方案2】:

    请在您的 mySecondClass 中添加字段:

    class mySecondClass {
    
        private $myFirstClass;
        private $myFirstClass2;
    
    }
    

    class mySecondClass {
    
        /**
         * @var myFirstClass 
         */
        private $myFirstClass;
    
        /**
         * @var myFirstClass 
         */
        private $myFirstClass2;
    
    }
    

    【讨论】:

    • 无关紧要,这不会改变任何东西 ;)
    • 它适用于我的环境(Linux 上的 NB81)。请尝试添加 PHPDoc cmets(已更新)。
    猜你喜欢
    • 1970-01-01
    • 2018-01-27
    • 2016-09-17
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多