[英]Type annotations of undeclared variables
我繼承了一個使用自制模板系統的項目,其工作方式如下:
# 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
由於extract
,傳遞給include_template
的變量在page.php
中可見,但是IDE(phpstorm)並不了解它們,因此它將其突出顯示為undefined,並且不提供自動補全等功能。有沒有辦法注釋page.php
(“裸”的php / html文件)中未聲明的變量,以便IDE可以看到它?
您必須在page.php中聲明它。 請參閱以下代碼。 它可以在PHPStorm中使用。
<?php
/**
* @var User $user
* @var Account $account
*/
?>
<h1><?= $user->name ?></h1>
<p>Balance: <?= $account->balance ?></p> etc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.