Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » PHP class autocomplete(How to add a class to autocomplete)
PHP class autocomplete [message #1233010] Sat, 18 January 2014 10:36 Go to next message
Tobias J is currently offline Tobias J
Messages: 1
Registered: January 2014
Junior Member
try to explain what my problem is. I have a library class which loads for me other classes and stores it in a public variable.

This is an example

/**
* Database class object
* @var $DB nCore_database
*/
public $DB;

/**
* Homepage class object
* @var $HP nCore_homepage
*/
public $HP;

/**
* Load nCore classes
* @access private
*/
private function loadCoreClass($nCoreClasses) {
    if(is_array($nCoreClasses) AND count($nCoreClasses) > 0) {
        foreach ($nCoreClasses AS $key => $value) {
            $key = strtolower($key);
            $value = strtolower($value);

            if(!class_exists("nCore_" . $value) AND file_exists(main_classes . "ncore/{$value}.php")) {
                include_once(main_classes . "ncore/{$value}.php");
                eval( "\$this->" . strtoupper($key) . " = new nCore_{$value}(\$this);" );
            }
        }
    }
}


In $nCore->DB is now my database stored with functions like: query(), getRowCount() etc.

When I type $nCore->DB-> there is no autocomplete. Is it possible to enable this in eclipse, so that when I type $nCore->DB-> the system will give me hints like: $ncore->DB->query(); When i load this class manually in a variable called only $db = new nCore_database(); it do what I want, but I want this library for me.

Hope you know an answer.
Re: PHP class autocomplete [message #1233587 is a reply to message #1233010] Mon, 20 January 2014 03:05 Go to previous messageGo to next message
Toshihiro Izumi is currently offline Toshihiro Izumi
Messages: 351
Registered: July 2009
Location: Japan
Senior Member
FYI,
PHP: Type hints for fields with Eclipse PDT - Stack Overflow
Re: PHP class autocomplete [message #1328461 is a reply to message #1233587] Fri, 02 May 2014 18:08 Go to previous messageGo to next message
Daniel Mising name is currently offline Daniel Mising name
Messages: 9
Registered: April 2011
Junior Member
Also, please don't use eval(), it makes old devs nervous. Instead it is neater to do this:

$key = strtoupper($key);
$classname = 'nCore_' . $value;
$this->{$key} = new $classname($this);
Re: PHP class autocomplete [message #1389163 is a reply to message #1328461] Fri, 27 June 2014 12:22 Go to previous message
Bill Krawiec is currently offline Bill Krawiec
Messages: 5
Registered: June 2014
Junior Member

Daniel Mising name wrote on Fri, 02 May 2014 18:08
Also, please don't use eval(), it makes old devs nervous.


Well it should make any dev nervous, because it is:


  1. dangerous piece of code opening potential security holes
  2. evidence of bad design, which reduces the readability of the code


There are some scenarious where this might be necessary. But your code, Tobias, is not one of them.

Daniel Mising name wrote on Fri, 02 May 2014 18:08
Instead it is neater to do this:

$key = strtoupper($key);
$classname = 'nCore_' . $value;
$this->{$key} = new $classname($this);


Braces around $key are unnecessary. You could use them to call strtoupper inside, but
this might look ugly:

$this->{strtoupper($key)} = new $classname($this);




Magento developer at pneumatyka



[Updated on: Tue, 01 July 2014 13:52]

Report message to a moderator

Previous Topic:DLTK problem - Syntax Error on double quotes !! Why ??
Next Topic:PHP Learner
Goto Forum:
  


Current Time: Tue Oct 21 20:05:45 GMT 2014

Powered by FUDForum. Page generated in 0.02057 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software