Framework: Trying to access array offset on value of type null

Created on 3 Dec 2019  路  18Comments  路  Source: laravel/framework

  • Laravel Version: 5.7.7
  • PHP Version: 7.4.0
  • Database Driver & Version:

Description:

Trying to access array offset on value of type null

Steps To Reproduce:

Perform any access or execute the 'php artisan' command

needs more info

Most helpful comment

I'm having the same issue when using laravel 6 with php 7.4

Step to reproduce

in your controller create new instance of any model and pass it to view something like

$banner = new Banner();

return view('back.banners.create', compact('banner'));

and in your view try to use old helper something like

old('title.en', $banner->title['en'])

Workaround to use the optional helper to ignore the error produced by php 7.4

old('title.ar', optional($banner->title)['en'])

in php 7.3 this was not an issue and the code worked fine I think the old helper need adjustment for php 7.4 to work like the old behaviour

All 18 comments

We'll need more information than this. Is this a fresh Laravel app. What's the stack trace?

Please provide some code

Please provide some code

The current situation is due to access to the default home page after the PHP version has been upgraded to version 7.4.

Having the same issue. I have a model with a jsonb field that is casted to an array, like this.

protected $casts = [
     'data' => 'array',
];

In PHP 7.3, when I dump the model, 'data' is an array (as expected). In PHP 7.4, 'data' is null.

Edit: Didn't notice the Laravel version on first post. I'm on Laravel 6.5.1

Laravel Version: 5.7.7

It Laravel 5.7 supposed to work with PHP 7.4?

I didn't catch the version here. 5.7 indeed doesn't supports PHP 7.4 and isn't maintained anymore.

Please check out our support policy on which versions we are currently supporting.

@driesvints The issue is present on 6.5.1

Edit: Please disregard this. I'm not being able to reproduce the issue on a fresh install on Laravel. The issue might be somewhere else.

I'm having the same issue when using laravel 6 with php 7.4

Step to reproduce

in your controller create new instance of any model and pass it to view something like

$banner = new Banner();

return view('back.banners.create', compact('banner'));

and in your view try to use old helper something like

old('title.en', $banner->title['en'])

Workaround to use the optional helper to ignore the error produced by php 7.4

old('title.ar', optional($banner->title)['en'])

in php 7.3 this was not an issue and the code worked fine I think the old helper need adjustment for php 7.4 to work like the old behaviour

According to PHP-Doc this is a Backwards Incompatible Change

Array-style access of non-arrays

Trying to use values of type null, bool, int, float or resource as an array (such as $null["key"]) will now generate a notice.

some note
... /vendor/illuminate/support/ServiceProvider.php

95:    protected function loadViewsFrom($path, $namespace)
96:    {
97:    --    if (is_array($this->app->config['view']['paths'])) {
97:   ++    if (isset($this->app->config['view']) && is_array($this->app->config['view']['paths'])) {

Had following configurations:

  • laravel/lumen-framework 5.7
  • php 7.4.2

downgrading to php 7.2 worked for me

Maybe in some case you try composer update first.

I didn't catch the version here. 5.7 indeed doesn't supports PHP 7.4 and isn't maintained anymore.

Please check out our support policy on which versions we are currently supporting.

I was having this same _"Trying to access array offset on value of type null."_ problem, and it referenced /vendor/egulias/email-validator/EmailValidator/Parser/Parser.php(147): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError().

This start happening for me after I upgraded my server to PHP 7.4.

And it was for a Laravel 5.8 (not 5.7) app. Upgrading to Laravel 6.x seemed to fix it.

this issue happened for me on laravel 5.8 on php 7.4. Downgrading the php to 7.3 fixed it.

@agharium 5.8 doesn't supports 7.4

@driesvints learned it the hard way.

same issue
Trying to access array offset on value of type null in F:\xampp\htdocs\mlmproject\admin\join.php on line 116

Hey everyone,

I'm locking this issue because it either has gone off-topic, become a dumping ground for things which shouldn't be in an issue tracker or is just too old. Please try to discuss things further on one of the below channels:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CupOfTea696 picture CupOfTea696  路  3Comments

ghost picture ghost  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

iivanov2 picture iivanov2  路  3Comments