Answer the question
In order to leave comments, you need to log in
How to explicitly set the type of a PHP variable in PhpStorm?
Faced with an unpleasant fact, unlike C #, non-strict typing reigns in PHP. When developing, I use the PhpStorm IDE, the problem is that some functions do not return a variable of an explicit type. Here is one such function (hello Symfony2):
$server = $em->getRepository('MyBundle:Server')->findOneById($id); // $server является неизвестным типом со стороны PhpStorm
$server = (Server)$em->getRepository('MyBundle:Server')->findOneById($id); // ошибка синтаксиса
Answer the question
In order to leave comments, you need to log in
If the problem is only code completion, use phpdoc
/** @var Server $server */
$server = $em->getRepository('MyBundle:Server')->findOneById($id);
You can also set up a meta instruction for the factory
confluence.jetbrains.com/display/PhpStorm/PhpStorm...
After writing the .phpstorm.meta.php file, be sure to restart the storm (in older versions it does not work without restarting)
and what are you clearly leading to? to server? I didn't see this in the documentation.
But phpdoc will help in this matter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question