我有一個應用程式,我在一個檔案 ( a.php) 中定義了一些變數,然后從另一個檔案 ( b.php) 中包含它。PHPStan 抱怨可能未定義的變數。
簡化示例:
一個.php:
$config['foo'] = 'bar';
b.php:
<?php
require 'a.php';
//new SlimApp($config)->run();
echo $config;
PHPStan 說:
------ ----------------------------------------
Line b.php
------ ----------------------------------------
:6 Variable $config might not be defined.
------ ----------------------------------------
另外:我不知道為什么,但如果我洗掉<?php開頭的行b.php,警告就會消失。
我怎樣才能讓 PHPStan 意識到$config實際定義?
順便說一句,我知道這個問題。這與我明確包含定義變數的檔案不同。
uj5u.com熱心網友回復:
一種解決方案:
/** @var array $config */你可以在檔案頂部阻止通知。
在此處查看更多資訊:github.com/phpstan/phpstan/issues/5815
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/535880.html
標籤:PHPphp斯坦
