1
foreach ($results as $obj) {
    $this->dates[$obj->getName()] = $obj;
}

This runs fine, but PHPStorm gives the hint,

Method getName not found in class.

Seems like there ought to be a way to give it a hint about the type of the object. How do I get it to recognize that this is an instance of a particular class like we can with method parameters? Something like

foreach ($results as MyClass $obj) {
BWhite
  • 713
  • 1
  • 7
  • 24

1 Answers1

1

The key is not adding the Doc hint above or a type hint inside the foreach like I tried, but below the line, inside the code block.

   foreach ($results as $obj) {
        /* @var $obj MyClass */
        $this->dates[$obj->getName()] = $obj;
   }
BWhite
  • 713
  • 1
  • 7
  • 24