A
A
Alxjzx1002020-10-27 12:55:07
PHP
Alxjzx100, 2020-10-27 12:55:07

PhpStorm, how to determine my own property value?

Hello.

Faced with the fact that PhpStorm does not understand the $this->db->database declaration in the request.

There are 2 databases in the project, when a query needs to address both at once, I get a bunch of errors from phpStorm.

For example

//$this->db2->database string "database2"
$this->db->query("SELECT table1.id, table2.name FROM table1 LEFT JOIN ".$this->db2->database.".users table2 ON table1.id = table2.id");


If instead of $this->db2->database write database2 - phpStorm likes everything, the errors disappear. As I understand it, it does not see the definition of $this->db2->database .

Is there any way to tell him that this is database2? Perhaps there is a special comment for such cases?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2020-10-27
@glaphire

I think that there is some error in the code and the storm swears correctly (the configs or the class for the second database are incorrectly configured).
The easiest way is to save $this->db2->database into a variable before the request and write phpdoc over it with a description of what it returns, then substitute $databaseName2 into the request.

/**
 * @var string $databaseName2
 */
$databaseName2 = $this->db2->database;

A note on the code - do not substitute values ​​into strings like this, it is better to use sprintf () or substitute only the final variable, rather than accessing objects in a chain.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question