This Question is Not Answered

1 "correct" answer available (4 pts) 1 "helpful" answer available (2 pts)
2 Replies Last post: Jun 26, 2013 1:33 AM by Michael Bladowski  
Michael Bladowski Newbie 15 posts since
Jun 25, 2013
Currently Being Moderated

Jun 25, 2013 6:57 PM

Method not found

dear all,

 

i am using an array to store several db connections inside, so at many lines i use this in my code:

 

$ret =  $this->db[$this->mode]['produkte']->sql_query("SELECT....");

 

of course phpstorm always says Method sql_query not found.

 

is there any way to let phpstorm know that this array $this->db is from class "db" ?

i know its working at other situations with special comments, but in this case i don´t know.

 

thanks for any help!

 

regards,

micha

Andriy Bazanov Master 4,050 posts since
May 28, 2010
Currently Being Moderated
Jun 26, 2013 1:27 PM in response to: Michael Bladowski
Re: Method not found

Hi there,

 

I do not think (although not 100% sure on this) that currently PhpStorm is able to provide type hints for two-dimensional arrays ( $var['first']['second'] ).  Single dimension ( $var['first'] ) -- easy.

 

If you can -- rewrite your code so only one or none at all dimensions is used, for example:

 

instead of $this->db[$this->mode]['bla-bla']

introduce function that takes 2 parameters, and you will use it this way: $this->getDB($this->mode, 'bla-bla');

 

Something like this:

/**

* Description ...

* @param ...

* @param ...

*

* @return Your_DB_CLass

*/

protected function getDB ($mode, $something) {

     return $this->db[$mode][$somehting];

}

or maybe even this way (if first parameter would be $this->mode all the time)

/**

* Description ...

* @param ...

*

* @return Your_DB_CLass

*/

protected function getDB ($something) {

     return $this->db[$this->mode][$somehting];

}

More Like This

  • Retrieving data ...