繁体   English   中英

未声明变量的类型注释

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM