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

Uncaught Error: Call to a member function getLanguages() on null #6

Closed
deevroman opened this issue Apr 8, 2021 · 1 comment
Closed
Assignees
Labels

Comments

@deevroman
Copy link

deevroman commented Apr 8, 2021

Code from README.md

echo LanguageDetector::detect(
    'My tailor is rich and Alison is in the kitchen with Bob.',
    ['en', 'de', 'fr', 'es']
);
PHP Fatal error:  Uncaught Error: Call to a member function getLanguages() on null in PATH/LanguageDetector/LanguageDetector.php:104
Stack trace:
#0 PATH(31): LanguageDetector\LanguageDetector::detect('My tailor is ri...', Array)
public static function detect($text, array $languages = []): self
{
    // All specified models have been loaded
    $diff = count($languages)
        ? array_diff(
                    self::$detector->getLanguages(),
                    $languages
                )
        : [];
    if (is_null(self::$detector) || count($diff)) {
        self::$detector = new self(null, $languages);
    }


    return self::$detector->evaluate($text);
}

Error on line self::$detector->getLanguages(),

Maybe before need to add:

if (is_null(self::$detector)) {
    self::$detector = new self(null, $languages);
}
@landrok
Copy link
Owner

landrok commented Apr 9, 2021

Hi @deevroman

I was sure that it had been tested but it surely wasn't enough.

I've just fixed and release v1.3.1.

Thanks for this catch.

@landrok landrok closed this as completed Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants