Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hasen39's avatar

Trying to access array offset on value of type null

i was working on laravel 5.7 and i upgrade to laravel 5.8 . in 5.7 it was working fine without error. but in 5.8 i get this error.

ErrorException
Trying to access array offset on value of type null 
0 likes
14 replies
hasen39's avatar

yes ,i already install 7.4 how can i use 7.3

jlrdw's avatar

Can you show code that caused the error, maybe some of us wants to check our 7.4 install to see if we also get the error. It will help narrow it down. Also as @bobbybouwmann mentioned, more of the error.

I use array's often in php and I have php 7.4, but no array problems yet.

1 like
hasen39's avatar

ignition error page

Illuminate\Foundation\Bootstrap\HandleExceptions::handleError :42
app/Http/Controllers/LinksController.php:42

my code



use Debugbar;

use Theme;

use MetaTag;

use Request;

 

class LinksController extends HomeController

{

    public function index(){

        $isuser = user_logged_in();

        $user = User::where('id', $isuser->id)->where('status', 1)->first();

        $totalLinks = UserLinks::where('user_id', $isuser->id)->count();

        $qlinks = array();

        $lnks = UserLinks::where('user_id', $isuser->id)->orderBy('id', 'DESC')->get();

        foreach($lnks as $link){

            $post = Posts::where('id', $link->post_id)->first();

            $category = Categories::where('id', $post['category'])->first();

            $qlinks[$link->id] = $link;

            $qlinks[$link->id]['post_title'] = $post['title'];

            $qlinks[$link->id]['post_image'] = $post['image'];

            $qlinks[$link->id]['post_link'] = $post['link'];

            $qlinks[$link->id]['post_category'] = $category['name'];

            $qlinks[$link->id]['post_category_slug'] = $category['slug'];

            $qlinks[$link->id]['post_tagline'] = $post['tagline'];

        }

jlrdw's avatar

Have you used the browser developer tools to see what's going on, also dd at a couple of places as needed to ensure you are getting expected results.

Also check your variables: https://wiki.php.net/rfc/notice-for-non-valid-array-container

Edit: I tested this https://laracasts.com/discuss/channels/guides/paginate-collection-simple-example-guide bottom example with some null values, no problem. I think (not sure however) you are getting a null key.

Snapey's avatar

try

            $qlinks[$link->id] = $link;

            $qlinks[$link->id] = array();   // extra line to initialise sub-array

            $qlinks[$link->id]['post_title'] = $post['title'];

1 like
claudios's avatar

had the same issue for 2 days now. Phew! tried to switch php versions 7.4 to 7.3 from local to inside vm still no luck

maculus1's avatar

Running the composer update command in solved this issue for me: composer update

MahaWarisKhan's avatar

I facing this issue on "trying to access array offset on value of type null" on {{ $product['category']['category_name'] }} {{ $product['subcategory']['subcategory_name'] }} {{ $product->product_name }} @extends('frontend.master_dashboard')

@section('main')

        <div class="container">

            <div class="breadcrumb">

                <a href="index.html" rel="nofollow"><i class="fi-rs-home mr-5"></i>Home</a>

                <span></span> <a href="shop-grid-right.html">{{ $product['category']['category_name'] }}</a> <span></span> {{ $product['subcategory']['subcategory_name'] }} <span></span>{{ $product->product_name }}

            </div>

        </div>

    </div>

    <div class="container mb-30">

        <div class="row">

            <div class="col-xl-10 col-lg-12 m-auto">
<div class="row mb-50 mt-30">

    <div class="col-md-6 col-sm-12 col-xs-12 mb-md-0 mb-sm-5">

        <div class="detail-gallery">

            <span class="zoom-icon"><i class="fi-rs-search"></i></span>

            <!-- MAIN SLIDES -->

            <div class="product-image-slider">

            	@foreach($multiImage as $img)

                <figure class="border-radius-10">

                    <img src="{{ asset($img->photo_name) }} " alt="product image" />

                </figure>

                @endforeach

            </div>

            <!-- THUMBNAILS -->

            <div class="slider-nav-thumbnails">

				@foreach($multiImage as $img)

Please or to participate in this conversation.