简体   繁体   English

从包含的文件NetBeans自动完成无法正常工作?

[英]NetBeans auto-completion from included file not working?

I have a file named config.php, and i have other files includes config.php. 我有一个名为config.php的文件,我有其他文件包括config.php。 When editing one of files, I use an object from config.php and it autocompletes name of the object. 编辑其中一个文件时,我使用config.php中的一个对象,它会自动填充对象的名称。 But, when i try to see functions or variables of this object (with ->), there is no auto-completion. 但是,当我尝试查看此对象的函数或变量(使用 - >)时,没有自动完成。 Is there any way to make it work? 有没有办法使它工作?

Note: I already added /* @var $myObject myType */ to config.php before the object definition. 注意:我已经在对象定义之前将/ * @var $ myObject myType * /添加到config.php。 Do I have to add that line to my every file includes config.php? 我是否必须将该行添加到我的每个文件中,包括config.php? That doesn't seem right. 这似乎不对。

Edit: Sample added. 编辑:添加样本。

Directory; 目录;

  • config.php config.php文件
  • index.php 的index.php
  • lib/test.class.php LIB / test.class.php

config.php; config.php文件;

<?php
define('ABSPATH', dirname(__FILE__));
include_once ABSPATH.'/lib/test.class.php';

/* @var $TestObj test */
$TestObj = new test();

// auto complete works here.
$TestObj->someFunction();
?>

index.php; index.php文件;

<?php
include_once 'config.php';

// here, auto completes object name
// not lists functions or variables after ->
$TestObj->someFunction();
?>

lib/test.class.php; LIB / test.class.php;

<?php
class test {
    public $var1;

    public function someFunction() {
        echo 'I am some function.';
        return 0;
    }
}
?>

It is working when i add /* @var $TestObj test */ to index.php but I will have a lot of files like that and there must be a better way than adding that line to all of files. 当我将/ * @var $ TestObj test * /添加到index.php时,它正在工作,但我会有很多这样的文件,并且必须有一个比将该行添加到所有文件更好的方法。

Make shure that all files of your project are in the project's include path (righ click project -> properties -> include path). 确保项目的所有文件都在项目的包含路径中(右键单击项目 - >属性 - >包含路径)。 Usually there is only the "global include path", which you configure in the NetBeans settings (eg to point to your PEAR directory). 通常只有“全局包含路径”,您在NetBeans设置中配置(例如,指向您的PEAR目录)。 Add all directories which contain source code you want auto completion for to this include path. 将包含您希望自动完成的源代码的所有目录添加到此包含路径。 Hint: This include path has nothing to do with the include_path used in PHP itself. 提示:这包含路径与PHP本身使用的include_path无关。

Also instead of using hints in the cient code: 而不是使用客户代码中的提示:

/* @var $TestObj test */
$TestObj->...

You should give the sources some more apidoc, eg: 你应该给源代码更多apidoc,例如:

<?php
class test {
    /**
     * @var SomeClass
     */
    public $var1;

    /**
     * @return int
     */
    public function someFunction() {
        echo 'I am some function.';
        return 0;
    }
}

because of the dynamic nature of PHP the IDE realies on this information to give right hints. 由于PHP的动态特性,IDE在此信息上实现了正确的提示。

Go to Tools->Options-> click on PHP Icon on top -> General tab -> find "Global include path" -> Add Folder -> 转到工具 - >选项 - >单击顶部的PHP图标 - >常规选项卡 - >查找“全局包含路径” - >添加文件夹 - >

if(onLinux) { choose /var/www; if(onLinux){choose / var / www; } if(onWindows) { choose c:\\path_to_htdocs or whatever; } if(onWindows){选择c:\\ path_to_htdocs或者其他; } }

Ah, too much programming for today.. :) 啊,今天编程太多.. :)

For me, this repaired autocompletion and ctrl+click on method call. 对我来说,这修复了自动完成和ctrl +点击方法调用。

From netbeans go to tools->options Go to editor selection and from code Completion select php for languages section. 从netbeans转到tools->options转到编辑器选择,从代码完成选择php for languages部分。 This will expand menu and you will see a section Code Completion for Class Methods 这将展开菜单,您将看到Code Completion for Class Methods部分

Set that configuration by selecting checkboxes on that section. 通过选择该部分的复选框来设置该配置。 在此输入图像描述

I hope I understood this right. 我希望我明白这一点。 I use netbeans too and I am able auto-complete after I change my netbeans settings. 我也使用netbeans,我可以在更改netbeans设置后自动完成。

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

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