[英]Type annotations of undeclared variables
I've inherited a project that uses a home-made templating system, which works like this: 我继承了一个使用自制模板系统的项目,其工作方式如下:
# main code
include_template('page.php', array('user' => $user, 'account' => $account));
# template 'engine'
function include_template($path, $vars) {
extract($vars);
include $path;
}
and the template "page.php" is an ordinary php/html file, eg: 模板“ page.php”是普通的php / html文件,例如:
<h1><?= $user->name ?></h1>
<p>Balance: <?= $account->balance ?></p> etc
The variables that are passed to include_template
are visible in page.php
because of extract
, but the IDE (phpstorm) has no clue about them, so it highlights them as undefined and doesn't provide autocompletion etc. Is there a way to annotate an undeclared variable in page.php
(a "bare" php/html file), so that the IDE can see it? 由于
extract
,传递给include_template
的变量在page.php
中可见,但是IDE(phpstorm)并不了解它们,因此它将其突出显示为undefined,并且不提供自动补全等功能。有没有办法注释page.php
(“裸”的php / html文件)中未声明的变量,以便IDE可以看到它?
You have to declare it inside page.php. 您必须在page.php中声明它。 See the following code.
请参阅以下代码。 It works in PHPStorm.
它可以在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.