Netbeans autocompletion when using singleton to retrieve an object instead of a new statement?

when I use the "new" operator to instantiate the class, netbeans has no problem with auto-filling the elements of the object.

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

but when I use singleton to retrieve an object, it cannot autocomplete the members in the resulting object.

getInstance code is as follows:

 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 get around this?

thanks!

+6
php netbeans
source share
1 answer

You can add a comment to indicate which type of $instance is before assigning it:

 /* @var $instance Singleton */ $instance = Singleton::getInstance(); 


And you will get autocomplete:


(source: pascal-martin.fr )

(Tested with recent netbeans nightly build)



Another solution would be to add a doc block 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 will also get auto-complete:


(source: pascal-martin.fr )

+12
source share

All Articles