我继承了一个使用自制模板系统的项目,其工作方式如下:
# main code
include_template('page.php', array('user' => $user, 'account' => $account));
# template 'engine'
function include_template($path, $vars) {
extract($vars);
include $path;
}
和模板“page.php”是一个普通的php / html文件,例如:
<h1><?= $user->name ?></h1>
<p>Balance: <?= $account->balance ?></p> etc
由于include_template
,传递给page.php
的变量在extract
中可见,但IDE(phpstorm)对它们没有任何线索,因此它将它们突出显示为未定义且不存在提供自动完成等。有没有办法在page.php
(一个“裸”的php / html文件)中注释未声明的变量,以便IDE可以看到它?
答案 0 :(得分:2)
你必须在page.php中声明它。请参阅以下代码。它适用于PHPStorm。
<?php
/**
* @var User $user
* @var Account $account
*/
?>
<h1><?= $user->name ?></h1>
<p>Balance: <?= $account->balance ?></p> etc