Skip to main content



      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 05:36 Go to next message
Eclipse UserFriend
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] Sun, 19 January 2014 22:05 Go to previous messageGo to next message
Eclipse UserFriend
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 14:08 Go to previous messageGo to next message
Eclipse UserFriend
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 08:22 Go to previous message
Eclipse UserFriend
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 09:52] by Moderator

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


Current Time: Fri Jul 04 12:03:18 EDT 2025

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

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

Back to the top