Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODX 3 lexicon->load() crashes $_SESSION not set #15373

Closed
BobRay opened this issue Feb 5, 2021 · 4 comments
Closed

MODX 3 lexicon->load() crashes $_SESSION not set #15373

BobRay opened this issue Feb 5, 2021 · 4 comments

Comments

@BobRay
Copy link
Contributor

BobRay commented Feb 5, 2021

Bug report

Summary

I no $_SESSION array is set, lexicon->load crashes.

Step to reproduce

Call lexicon->load() with no $_SESSION set and $modx->context set to 'mgr'.

Here is the offending code (around line 189 of core/src/Revolution/modLexicon.php)

if ($this->modx->context && $this->modx->context->get('key') == 'mgr') {
            $defaultLanguage = $this->modx->getOption('manager_language', $_SESSION,
                $this->modx->getOption('cultureKey', null, 'en'));
        } else {
            $defaultLanguage = $this->modx->getOption('cultureKey', null, 'en');
        }

This will break testing code. (i.e. Unit, Integration, or Acceptance test) that call $lexicon->load();.

There are a number ways to fix this. This is one (just above the first getOption() call), but I'm not sure it's the best:

if (! isset($_SESSION)) {
    $_SESSION = null;
}

Environment

MODX 3, Windows 10, apache

@Mark-H
Copy link
Collaborator

Mark-H commented Feb 5, 2021

What do you mean exactly by "crashes"? Is it causing an error or unexpected behavior downstream?

@BobRay
Copy link
Contributor Author

BobRay commented Feb 6, 2021

Sorry, attempting to access a member of an array that doesn't exist throws a PHP error: Unknown variable $_SESSION.

@BobRay
Copy link
Contributor Author

BobRay commented Feb 6, 2021

I think a better solution is to put this above the first getOption() call:

$_SESSION = isset($_SESSION)? $_SESSION : array();

@Ibochkarev
Copy link
Collaborator

Fixed #15377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants