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 關注
- 305 瀏覽
添加回答
舉報