Slide 1
Excellent Education Program
Innovative Methods of Teaching

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cum sociis natoque penatibus et magnis dis parturient.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 3
Learning Through Play
Find a Class for your Children

Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis.

previous arrow
next arrow

PHP Laravel Error: Trying to access array offset on value of type null

Spread the Knowledge

Environment:
Laravel Version: 5.5
PHP Version: 7.4.0

Error stack trace:
Message: Trying to access array offset on value of type null

Sample code that gave me error:
$filterConfig = $request->get('filterConfig', null);
$showAll = $filterConfig['show']['all'] === 'true'? true: false;

The error was coming because $filterConfig was getting initialized by null in the first line and I was fetching $filterConfig[‘show’][‘all’] in the second line. Hence, it was throwing an error by saying Trying to access array offset on value of type null

NOTE: This error only comes if you have upgraded to PHP 7.4

Solution:

if (isset($filterConfig) && isset($filterConfig['show']['all'])) {
$showAll = true;
} else {
$showAll = false;
}

Chetan