尝试访问类型为 null 的值的数组偏移量

Ran*_*ame 12 php php-7.4

从 php 7.1 迁移到 7.4。我们有大约 500 个 API 功能测试,其中一些在迁移完成后开始失败并出现错误。这些测试以前到处都通过,现在到处都失败了——不是全部,只有 39 个。

环境信息:

  • php 7.4
  • 编码接收
  • yii2

堆栈跟踪:

...\api\vendor\codeception\codeception\src\Codeception\Subscriber\ErrorHandler.php:83
...\api\tests\functional\SomeFileHereCest.php:72
...\api\vendor\codeception\codeception\src\Codeception\Lib\Di.php:127
...\api\vendor\codeception\codeception\src\Codeception\Test\Cest.php:138
...\api\vendor\codeception\codeception\src\Codeception\Test\Cest.php:97
...\api\vendor\codeception\codeception\src\Codeception\Test\Cest.php:80
...\api\vendor\codeception\codeception\src\Codeception\Test\Test.php:88
... more stuff here, not important
Run Code Online (Sandbox Code Playgroud)

由于ErrorHandler.php:83这只是捕获错误,让我们看看SomeFileHereCest.php:72

// declaration of the apiPrefix variable in the class.
protected $apiPrefix;
//...

public function _before(FunctionalTester $I)
{
    $this->apiPrefix = $this->config['backend']['api_prefix']; // this is the line 72
    //... more similar stuff later
Run Code Online (Sandbox Code Playgroud)

所以$this->config['backend']['api_prefix']这是一个字符串(“v1”)

我不明白这个问题在哪里以及如何更深入地研究它。有任何想法吗?

del*_*8uk 14

听起来你的变量没有设置。

检查以下 isset 调用:

isset($this->config); 
isset($this->config['backend']);
isset($this->config['backend']['api_prefix']);
Run Code Online (Sandbox Code Playgroud)

您实际上可以在一个 isset 调用 ( isset($x, $y, $z)) 中检查多个变量,但这会让您看到具体缺少哪个变量