Задать вопрос
@html_student
Молодой и глупый.

Ошибка trying to access array offset on value of type null in?

if ( is_home() ) {
			if ( $this->tree["main"]["home"]["options"] != null ) {
				$options = $this->tree["main"]["home"]["options"];
			} elseif ( $this->tree["main"]["options"] != null ) {
				$options = $this->tree["main"]["options"];
			} else {
				$options = $this->tree["all"]["options"];
			}
		}


ругается на
if ( $this->tree["main"]["home"]["options"] != null ) {

и
} elseif ( $this->tree["main"]["options"] != null ) {

Появилось после переключения на PHP 8 , я только не пойму, мне надо проверку на is_array сделать? или isset?
Получается
if ( is_home() ) {
			if (isset($this->tree["main"]["home"]["options"] )) {
				$options = $this->tree["main"]["home"]["options"];
			} elseif (isset($this->tree["main"]["options"])) {
				$options = $this->tree["main"]["options"];
			} else {
				$options = $this->tree["all"]["options"];
			}
		}

Так убираем ошибки
Но
$options = $this->tree["all"]["options"];
Тоже ругается
Trying to access array offset on value of type null
  • Вопрос задан
  • 175 просмотров
Подписаться 1 Простой Комментировать
Помогут разобраться в теме Все курсы
  • Skillfactory
    Профессия Fullstack веб-разработчик на JavaScript и PHP
    20 месяцев
    Далее
  • Хекслет
    PHP-разработчик
    10 месяцев
    Далее
  • Skillbox
    PHP-разработчик. Базовый уровень
    3 месяца
    Далее
Пригласить эксперта
Ответы на вопрос 1
batyrmastyr
@batyrmastyr
Isset, причём в форме
$options = $this->tree["main"]["home"]["options"] ?? $this->tree["main"]["options"] ?? $this->tree["all"]["options"];

Но сперва прикинуть какой из уровней оказывается null вместо массива: $this->tree["main"]["home"], $this->tree["main"] или $this->tree и насколько такая ситуация нормальна?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы