0

My PhpStorm can't find the method of an singleton class when I direct call it.

this works:

$db = Database::getInstance();
/** @var Database $db */
$this->db = $db->getDatabase(IMS_DB);

this not

/** @var Database Database::getInstance */
$this->db = Database::getInstance()->getDatabase(IMS_DB);

It says cannot find method getDatabase.

enter image description here

Any Ideas?

4
  • Hi and welcome to Stack Overflow, please take a time to go through the welcome tour to know your way around here (and also to earn your first badge), read how to create a Minimal, Complete, and Verifiable example and also check How to Ask Good Questions so you increase your chances to get feedback and useful answers. Commented Jul 10, 2017 at 18:18
  • Please elaborate by giving a more detailed example and describe exactly what step you took and what didn't work as expected. Commented Jul 10, 2017 at 18:21
  • 1
    "Any Ideas?" yes -- you last PHPDoc is wrong -- it does not work like that. You cannot typehint some method in another class this way. Typehinting like that works for local variables (like in first place, where you typehint $db variable). If you need typehint return type of Database::getInstance() then it has to be done in that Database class. Commented Jul 10, 2017 at 18:54
  • Your right. @LazyOne i made a mistake at the Database Class. Set the right return type there fixed the problem. Thx Commented Jul 11, 2017 at 7:39

1 Answer 1

1

You need to teach your IDE what getInstance() is actually returning, so you need to add phpDoc to Database::getInstance().

class Database

/**
* @return self
*/
public static function getInstance(){
    //code...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.