Log's barking about this one:

if (isset($_SESSION['userid']) && $_SESSION['userid']) return $_SESSION['userid'];

I'm thinking that if isset() is falsy then the logical AND makes it evaluate the session variable anyway, so "undefined array key"? Is that correct?

    No, it looks fine to me: , although the whole test can be simplified to just !empty($_SESSION['userid']).

    If you add linebreaks so that each occurrence of $_SESSION['userid'] is on a separate line, the line number in the log will be able to point to the occurrence it finds so offensive.

      No, it looks fine to me: , although the whole test can be simplified to just !empty($_SESSION['userid']).

      If you add linebreaks so that each occurrence of $_SESSION['userid'] is on a separate line, the line number in the log will be able to point to the occurrence it finds so offensive.

        I agree it looks correct though could be slimmed down a bit if you wanted to - it's possible you could also just cut it to return $_SESSION['userid'] ?? null;

          Write a Reply...