尝试访问类型为null的值的数组偏移量 [英] Trying to access array offset on value of type null

查看:749
本文介绍了尝试访问类型为null的值的数组偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从php 7.1迁移到7.4.我们有500个针对API的功能测试,其中一些测试在迁移完成后因失败而失败.这些测试无处不在,现在无处不在-并非全部,只有39种.

Migrating from php 7.1 to 7.4. We have like 500 functional tests for an API, and some of them started to fail with an error after the migration was complete. These tests were passing before everywhere, and now fail everywhere - not all, just 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

由于ErrorHandler.php:83只是在捕获错误,因此让我们来看一下SomeFileHereCest.php:72:

Since ErrorHandler.php:83 this is just catching the error, let's look at the 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

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

So the $this->config['backend']['api_prefix'] this is a string("v1")

我看不出这个问题在哪里以及如何更深入地研究它.有什么想法吗?

And I dont see where is the issue with this and how to dig into it deeper. Any ideas?

推荐答案

未设置您的变量之类的声音.

Sounds like your variable isn't set.

检查以下isset调用:

Check with the following isset calls:

isset($this->config); 
isset($this->config['backend']);
isset($this->config['backend']['api_prefix']);

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

You can actually check multiple vars in one isset call (isset($x, $y, $z)), but this will let you see which var specifically is missing

这篇关于尝试访问类型为null的值的数组偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆