NetBeans从包含的文件自动完成无法正常工作? [英] NetBeans auto-completion from included file not working?

查看:78
本文介绍了NetBeans从包含的文件自动完成无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为config.php的文件,并且我还有其他文件包括config.php.编辑文件之一时,我使用config.php中的对象,它会自动完成该对象的名称.但是,当我尝试查看此对象的功能或变量时(带有->),没有自动完成功能.有什么办法可以使它工作?

I have a file named config.php, and i have other files includes config.php. When editing one of files, I use an object from config.php and it autocompletes name of the object. 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?

注意:我已经在对象定义之前将/* @var $ myObject myType */添加到config.php中.我是否必须将该行添加到每个包含config.php的文件中?这似乎不正确.

Note: I already added /* @var $myObject myType */ to config.php before the object definition. Do I have to add that line to my every file includes config.php? That doesn't seem right.

添加了示例.

目录;

  • config.php
  • index.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;
    }
}
?>

当我将/* @var $ TestObj test */添加到index.php时,它是有效的,但是我将有很多类似的文件,并且必须有比将这一行添加到所有文件中更好的方法.

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.

推荐答案

请确保您项目的所有文件都在项目的include路径中(右键单击project-> properties-> include path).通常只有在NetBeans设置中配置的全局包含路径"(例如,指向PEAR目录).将包含您要自动完成的源代码的所有目录添加到此包含路径.提示:此包含路径与PHP本身使用的include_path无关.

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 (e.g. to point to your PEAR directory). 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.

也不要在科学代码中使用提示:

Also instead of using hints in the cient code:

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

您应该给源提供更多的apidoc,例如:

You should give the sources some more apidoc, e.g.:

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

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

由于PHP具有动态特性,因此IDE会根据此信息提供正确的提示.

because of the dynamic nature of PHP the IDE realies on this information to give right hints.

这篇关于NetBeans从包含的文件自动完成无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆