3 回答

TA贡献1840条经验 获得超5个赞
听起来你的变量没有设置。
检查以下 isset 调用:
isset($this->config);
isset($this->config['backend']);
isset($this->config['backend']['api_prefix']);
您实际上可以在一次 isset 调用 ( isset($x, $y, $z)) 中检查多个 var,但这会让您查看具体缺少哪个 var

TA贡献2011条经验 获得超2个赞
使用 (??) ( double question mark operator) (" null coalescing operator") 来避免未设置的数组。
这个单元测试给了我“成功”
class PhpTest extends TestCase
{
public function test_php_74()
{
//Trying to access array offset on value of type null
$this->assertSame('7.4.9', phpversion());
$a = null;
$this->assertTrue($a ?? true);
$this->assertTrue($a['a'] ?? true);
$this->assertTrue($a['a']['a'] ?? true);
$a = [];
$this->assertSame([], $a);
$this->assertTrue($a['a'] ?? true);
$this->assertTrue($a['a']['a'] ?? true);
}
}

TA贡献1900条经验 获得超5个赞
它与 PHP 7.4 问题有关。解决方案是我们可以将 isset 放在 PHP 或 Laravel Blade 旧代码中
@foreach ($widgets->get('dashboard') as $widget)
{!! $widget->render() !!}
@endforeach
使用 isset 更新新代码
@if(isset($Widget))
@foreach ($widgets->get('dashboard') as $widget)
{!! $widget->render() !!}
@endforeach
@endif
- 3 回答
- 0 关注
- 268 浏览
添加回答
举报