{"id":9671,"date":"2020-01-28T11:20:46","date_gmt":"2020-01-28T11:20:46","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=9671"},"modified":"2021-11-13T06:09:36","modified_gmt":"2021-11-13T06:09:36","slug":"php-laravel-error-trying-to-access-array-offset-on-value-of-type-null","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/php-laravel-error-trying-to-access-array-offset-on-value-of-type-null\/","title":{"rendered":"PHP Laravel Error: Trying to access array offset on value of type null"},"content":{"rendered":"\n<p><strong>Environment:<\/strong><br>Laravel Version: 5.5<br>PHP Version: 7.4.0<\/p>\n\n\n\n<p><strong>Error stack trace:<\/strong><br><code>Message: Trying to access array offset on value of type null<\/code><\/p>\n\n\n\n<p><strong>Sample code that gave me error:<\/strong><br><code>$filterConfig = $request-&gt;get('filterConfig', null);<\/code><br><code>$showAll = $filterConfig['show']['all'] === 'true'? true: false;<\/code><br><br>The error was coming because  $filterConfig was getting initialized by null in the first line and I was fetching  $filterConfig[&#8216;show&#8217;][&#8216;all&#8217;] in the second line. Hence, it was throwing an error by saying Trying to access array offset on value of type null<br><br><strong><u>NOTE:<\/u><\/strong> <strong>This error only comes if you have upgraded to PHP 7.4<\/strong><\/p>\n\n\n\n<p><strong>Solution:<\/strong><br><\/p>\n\n\n\n<p><code>if (isset($filterConfig) &amp;&amp; isset($filterConfig['show']['all'])) {<br>   $showAll = true;<br>} else {<br>   $showAll = false;<br> }<\/code><\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_46013\"><iframe loading=\"lazy\"  id=\"_ytid_81424\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_46013\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Environment:Laravel Version: 5.5PHP 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-&gt;get(&#8216;filterConfig&#8217;, null);$showAll = $filterConfig[&#8216;show&#8217;][&#8216;all&#8217;] ===&#8230; <\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5150],"tags":[],"class_list":["post-9671","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=9671"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9671\/revisions"}],"predecessor-version":[{"id":24988,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9671\/revisions\/24988"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=9671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=9671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=9671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}