{"record":{"id":"b19099fa2c9d22bb","repo":"serbanghita/Mobile-Detect","slug":"no-such-method-exists-name","errorCode":null,"errorMessage":"No such method exists: $name","messagePattern":"No such method exists: \\$name","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/MobileDetect.php","lineNumber":1395,"sourceCode":"        }\n\n        return false;\n    }\n\n    /**\n     * Magic overloading method.\n     *\n     * @param string $name\n     * @param array $arguments\n     * @return bool\n     * @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is'\n     * @throws \\Exception\n     */\n    public function __call(string $name, array $arguments): bool\n    {\n        // make sure the name starts with 'is', otherwise\n        if (!str_starts_with($name, 'is')) {\n            throw new BadMethodCallException(\"No such method exists: $name\");\n        }\n\n        $ruleName = substr($name, 2);\n\n        return $this->is($ruleName);\n    }\n\n    /**\n     * Check if the device is mobile.\n     * Returns true if any type of mobile device detected, including special ones\n     * @return bool\n     * @throws MobileDetectException\n     */\n    public function isMobile(): bool\n    {\n        if (!$this->hasUserAgent()) {\n            throw new MobileDetectException('No valid user-agent has been set.', MobileDetectExceptionCode::INVALID_USER_AGENT_ERR);\n        }","sourceCodeStart":1377,"sourceCodeEnd":1413,"githubUrl":"https://github.com/serbanghita/Mobile-Detect/blob/6ab7b0404df1da8da2aa2c56634362842d9c2a23/src/MobileDetect.php#L1377-L1413","documentation":"MobileDetect implements its magic isXXXX() API through __call() (src/MobileDetect.php:1395): any undefined method whose name starts with 'is' (isIphone(), isAndroidOS(), isChrome()) is forwarded to is($ruleName) and matched against the rule arrays. Any other undefined method name throws this BadMethodCallException instead of returning null or false — a fail-fast design so typos in real method names surface immediately.","triggerScenarios":"$detect->getUserAge() (typo of getUserAgent), $detect->detectMobile(), $detect->mobileDetect(), or dynamic calls $detect->{$method}() where $method comes from config/routing and doesn't begin with 'is'. Note that names that DO start with 'is' never throw here — they fall through to is() and match against the rules (unknown rules simply return false).","commonSituations":"Calls to methods removed or renamed across versions (e.g. older getters); IDE auto-completion or AI-generated code inventing names like detectMobile() or userAgent(); dynamic dispatch built from user input without a whitelist.","solutions":["Check the real API first: method_exists($detect, $name) for concrete methods; for the magic rules, verify the suffix after 'is' against the rule arrays (getRules(), or the vendor fixtures in tests/providers/vendors/).","Correct the call to an existing name: setUserAgent(), getUserAgent(), isMobile(), isTablet(), is(), version().","For dynamic dispatch, whitelist before calling: allow only method_exists() names or strings matching /^is[A-Z]/."],"exampleFix":"// before\n$detect->getMobileHeaders(); // BadMethodCallException: No such method exists: getMobileHeaders\n\n// after\n$detect->setUserAgent($ua);\n$isAndroid = $detect->isAndroidOS(); // 'AndroidOS' is a real operating-system rule\n$isMobile  = $detect->isMobile();     // concrete method","handlingStrategy":"validation","validationCode":"$method = 'is' . ucfirst($rule);\nif (!method_exists($detect, $method) && !preg_match('/^is[A-Z]/', $method)) {\n    throw new \\BadMethodCallException(\"Unknown detection rule: $rule\");\n}\n$result = $detect->$method();","typeGuard":"function isMagicDetectorCall(string $method): bool\n{\n    // concrete API first, then the 'is' + RuleName convention handled by __call\n    return method_exists(MobileDetect::class, $method)\n        || (str_starts_with($method, 'is') && strlen($method) > 2);\n}","tryCatchPattern":"try {\n    $ok = $detect->{$name}();\n} catch (\\BadMethodCallException $e) {\n    // $name came from config/input and maps to no method; skip\n    $ok = false;\n}","preventionTips":["Cross-check rule names against getRules() or the vendor fixtures in tests/providers/vendors/ before hardcoding isXXXX() calls.","Never feed raw user input into dynamic method names; whitelist first.","Run static analysis on callers — __call's @throws BadMethodCallException documents the contract."],"tags":["magic-methods","bad-method-call","api-misuse","php","user-agent"],"backgroundTag":"undefined-method-call","analyzedSha":"6ab7b0404df1da8da2aa2c56634362842d9c2a23","analyzedAt":"2026-08-21T04:49:48.090Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}