tags:

views:

107

answers:

1

when i use the 'new' operator to instantiate a class, netbeans has no problem to autocomplete the members of the object.

$instance = new Singleton();
$instance-> // shows test() method

but when i use a singleton to retrieve an object it cannot autocomplete the members in the object retrieved.

the getInstance code looks like this:

public function test() {
    echo "hello";
}

public static function getInstance() {
if ( ! is_object(self::$_instance)) {
    self::$_instance = new self();
    self::$_instance->initialize();
}
return self::$_instance;
}

so i use:

$instance = Singleton::getInstance();
$instance-> // no autocompletion!

does anyone have the same problem?

how do i work around it?

thanks!

+2  A: 
Pascal MARTIN
i think the second method is better cause then i dont have to add comment every time before calling it. thanks a lot!! u saved my year!! +2 (1 invisible point):)
never_had_a_name
You're welcome :-) ;; Yes, the second solution if often better, generally speaking ;; but the first one can be useful in two cases : when you cannot modify the class *(a library, for example)*, and when the method you call can return instances of different classes, depending on the parameter *(i.e. a factory method, for example)*
Pascal MARTIN