【发布时间】:2021-11-24 22:06:54
【问题描述】:
我有一个包含在函数中的配置文件,如下所示:
function getConnection() {
include 'config.php';
return new Connection($config['host']);
}
问题是让 Psalm 从配置文件中识别出$config 变量。可能的?最好使用数组形状表示法。
【问题讨论】:
标签: psalm-php
我有一个包含在函数中的配置文件,如下所示:
function getConnection() {
include 'config.php';
return new Connection($config['host']);
}
问题是让 Psalm 从配置文件中识别出$config 变量。可能的?最好使用数组形状表示法。
【问题讨论】:
标签: psalm-php
通过在包含行上方添加/** @var ... 注释解决:
function getConnection() {
/** @var array{host: string} $config */
include 'config.php';
return new Connection($config['host']);
}
【讨论】: