Skip to content
Advertisement

NetBeans auto-completion from included file not working?

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?

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.

Edit: Sample added.

Directory;

  • config.php
  • index.php
  • lib/test.class.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;

<?php
include_once 'config.php';

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

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.

Advertisement

Answer

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->...

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;
    }
}

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

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement