Skip to content
Advertisement

PHP – Unidentified index in error log even though using isset to check for session variable

I am running the following check in PHP (in a Slim middleware) to make sure that a certain session variable exists:

JavaScript

However, my error log is swamped with the following:

JavaScript

What can I do to have this not show as an error?

I found a solution here: PHP: Notice Undefined index even using isset but my case is different as I’m not accessing the variable prior to the check.

Advertisement

Answer

You can use array_key_exists instead of isset

JavaScript

Here you can find the docs: https://www.php.net/manual/es/function.array-key-exists.php

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement