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!
You could add a comment to indicate of which type $instance
is, before assigning it :
/* @var $instance Singleton */
$instance = Singleton::getInstance();
And you'd get autocompletion :
(source: pascal-martin.fr)
(Tested with a recent nightly build of netbeans)
Another solution would be to add a docblock to the declaration of your getInstance()
method, to indicate that it returns an instance of the Singleton
class :
/**
* @return Singleton
*/
public static function getInstance() {
}
And, then, you'll also get autocompletion :
(source: pascal-martin.fr)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With