NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
[resolved] Code Insight Problem


Joined: 19 Apr 2009
Posts: 9
Location: Guelph, ON Canada
Reply with quote
I have a small problem with code insight in a project I'm working on. I've defined a class with a static method to return a PDO resource database connection. The code is this:

Code:

class dbConn {
   
   private static $conn;
   
   private function __construct(){}
   
   
   static public function getConn ($dsn, $user, $pass) {
      if (is_null(self::$conn)) {
         self::$conn = new PDO($dsn, $user, $pass);
      }
      return self::$conn;
   }
}


I'm using this code in the constructor of another class to get a database connection with the following code:

Code:

$this->db = dbConn::getConn($conn, $user, $pass);


The problem is that $this->db is not recognised by PHPED as a PDO resource. When I use the property the IDE doesn't give me any code insight on the property meaning I have to manually type all of the methods, etc. Is this a bug or is there anything I can do to force code insight to recognise $this->db as a PDO resource?

Thanks.
View user's profileFind all posts by JCookSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
your example works perfectly well:




If you're still experiencing the problem, it must be something else.


Last edited by dmitri on Thu May 07, 2009 1:44 pm; edited 1 time in total

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


Joined: 19 Apr 2009
Posts: 9
Location: Guelph, ON Canada
Reply with quote
Thanks Dimitri. I can see that it works perfectly for you but unfortunately it doesn't for me. Do you have any suggestions as to what I can do to 'reset' the code insight for the file these classes are declared in? Are there any settings in PHPED that might affect this. The only thing you've done slightly differently to me is the order in which the classes are declared. In my file dbConn is declared after the class that calls it in setting $this->db. Could this be the problem?

Thanks again for your help.
View user's profileFind all posts by JCookSend private message


Joined: 19 Apr 2009
Posts: 9
Location: Guelph, ON Canada
Reply with quote
I worked it out. I'm new to the PHPdoc format and had put a comment in the code saying '@var resource A PDO resource representing the connection to the database'. PHPED interpreted this as meaning that the variable $this->db was of the type 'resource'. As soon as I changed the comment to '@var PDO A PDO resource representing the connection to the database' it works without a problem.

Thanks again Dimitri and sorry for wasting your time.
View user's profileFind all posts by JCookSend private message
[resolved] Code Insight Problem
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