NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Code completion for singleton pattern *resolved*


Joined: 30 Oct 2004
Posts: 8
Reply with quote
Hello,

Code completion does not seem to work with the following singleton pattern:

Code:

class singleton
{
    function &getInstance ($class)
    // implements the 'singleton' design pattern.
    {
        static $instances = array();  // array of instance names
       
        if (!array_key_exists($class, $instances)) {
            // instance does not exist, so create it
            $instances[$class] = new $class;
        } // if
       
        $instance =& $instances[$class];
       
        return $instance;
       
    } // getInstance
   
} // singleton

require_once 'std.datevalidation.class.inc';
$dateobj =& singleton::getInstance('DateClass');



$dateobj-> does not pull up any function list.

Is there a way to get this code completion to work? Will it work in a future version? Thanks.
View user's profileFind all posts by cayatesSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
type of object instance returned by that class is known only at run-time and therefore to get code completion working you need to add type hint.
Read FAQ topic related to type hints:
http://forum.nusphere.com/tip-type-hints-t1563.html

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


Joined: 30 Oct 2004
Posts: 8
Reply with quote
Thanks.
View user's profileFind all posts by cayatesSend private message


Joined: 17 Apr 2007
Posts: 7
Reply with quote
dmitri wrote:
type of object instance returned by that class is known only at run-time and therefore to get code completion working you need to add type hint.
Read FAQ topic related to type hints:
http://forum.nusphere.com/tip-type-hints-t1563.html


that doesn't seem to address the original problem, which i am now running in to.

in class tm, i have a singleton generator. $newobj = tm::generate_singleton('user');. at this point, $newobj contains an object of class 'user'. however, phped thinks that $newobj is in the tm class instead. i can't use the phpdoc "returns" syntax since the object type varies depending on how the function is called. is there any resolution for this?
View user's profileFind all posts by jsdSend private message


Joined: 14 Jun 2007
Posts: 67
Reply with quote
Code:
/** @var user */
$newobj = tm::generate_singleton('user');
View user's profileFind all posts by CjungeSend private message
Code completion for singleton pattern *resolved*
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