Reputation: 3461
I am using Yii2 framework in PhpStorm.
My problem arises in views when I am using $this->render
function to include another code of snippet inside my main file with some variables.
The code itself works perfectly I just have a problem with highlightings.
This is my code:
<?php
echo $this->render('commentsBlock', [
"comments" => $comments,
'deleteURL' => $deleteURL,
'editURL' => $editURL,
]);
?>
The code above renders commentsBlock.php and content of that target file is below:
As you can see the PhpStorm thinks that variables are not declared when they are defined.
I know that I need to add some comment which tells the IDE that vars do exist but what I tried did not work so far.
I did this:
But it is not highlighting.
Any ideas on how to write properly this comment section to trick IDE to highlight my variables?
Upvotes: 3
Views: 1554
Reputation: 18021
Use vardoc like this:
/* @var $comments array */
This syntax is a bit different from phpdoc standard (notice the variable name and type switched places) but it's widely recognised by IDEs (including PhpStorm).
For more references see this answer for example.
Upvotes: 9