NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Singleton and code completion


Joined: 20 Jan 2009
Posts: 2
Reply with quote
I have a special class which is a singleton. I'm using phpdocs to help but after calling getInstance code completion always fails.

example:

Code:
class SingletonExample
{

/**
* Container for instance
* @var SingletonExample
*/
protected static $instance;


/*
* etc, etc
*/

/**
* Create instance if it doesn't already exist, return instance.
* @returns SingletonExample
*/
    public static function getInstance()
    {
        if (!(self::$instance instanceof SingletonExample)) {
            self::$instance = new SingletonExample();
        }
        return self::$instance;
    }
}


When I go to call it elsewhere:

Code:
$se = SingletonExample::getInstance();

Code completion doesn't work, $se->[tab]
'Code completion is not available due to the following error(s):
Failed to identify type of "$se" local variable'
Even though I am providing two hints, one by specifying what the method returns and one by specifying the type of the actual instance variable.
View user's profileFind all posts by boxmonkeySend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Hmm, your sample works pretty fine in PhpED:


probably you have another problem. Please check that Code Explorer shows SingletonExample class. If it does not, make sure that the file with this class is in the project, or in one of the directories listed in Code Insight Includes list. Finally, check that file has an extension associated with PHP5.

Quote:
Even though I am providing two hints, one by specifying what the method returns and one by specifying the type of the actual instance variable.

neither is required in your case because this code is not polymorphic and all types are clearly known without hints. See short version below:


But, if you used something like below, it would require hint.
Code:
function ($clsname) {
   return new $clsname;
}

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 20 Jan 2009
Posts: 2
Reply with quote
In case anyone else is having this issue, I was able to resolve it by re-creating my workspace and project, which was originally created with an older version of PhpEdD.
View user's profileFind all posts by boxmonkeySend private message
Singleton and code completion
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic