0

i'm trying to troubleshoot a staff directory system that's built by someone else. it shows up fine on php5.6 but we were told to move to at least php7.4 by May this year. so i tried running simulations using xampp php7.4 on my laptop. but i got this error :

Uncaught Exception

Trying to access array offset on value of type null

Origin

app\functions\language.php on line 33

which corresponds to this line

function language_name() {
    return Registry::get('language')['name'];
}

i've tried googling for solutions but came up with nothing. i'm not programming savvy and the guy who built this system has transferred out and cannot be reached so i'm out of options. any help is very appreciated.

1 Answer 1

0

it's mean Registry::get('language') returns null. In php 5.6 it only give notice/warning but in php 7.4 it throws error.

The solution is to use isset to check if it exists or not, or maybe just ternary operator like below:

function language_name() {
    return Registry::get('language')['name'] ?? 'en';
}

You can change en to default language or maybe just null value.

Sign up to request clarification or add additional context in comments.

1 Comment

i wanted to use isset but i don't know how or where to use the command. but your solution works great. well, now the system throws another error message but at least we're going somewhere. thanks Muhammad Dyas!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.