A
A
Alexey Konovalov2018-08-22 19:55:32
phpstorm
Alexey Konovalov, 2018-08-22 19:55:32

How to explicitly set the class of a variable?

Hello! When the array contains a list of objects and we loop through it, calling each object. Or when the entry looks like this:

$class = '\notification\\'.$row['mode'].'\\'.str_replace(" ", "", ucwords(str_replace("_", " ", $row['model']))) . 'Notification';
  if (class_exists($class)){
    $notifi = new $class($this);
    $notifi->createObject($row);
  }

PHPStorm writes that the createObject method does not exist. It turns out that when working with the $notifi object , hints on existing methods are not displayed and you have to constantly climb into the class to remember.
How in such cases to let PHPStorm know what kind of class it is?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2018-08-22
@Alk90

Have you heard of dockblocks?/** @var MyObject $notify */

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question