{"record":{"id":"d02ce8f6b90e27ac","repo":"yiisoft/yii2","slug":"calling-unknown-method-class-name","errorCode":null,"errorMessage":"Calling unknown method: {class}::{name}()","messagePattern":"Calling unknown method: (.+?)::(.+?)\\(\\)","errorType":"exception","errorClass":"UnknownMethodException","httpStatus":null,"severity":"error","filePath":"framework/base/BaseObject.php","lineNumber":223,"sourceCode":"            $this->$setter(null);\n        } elseif (method_exists($this, 'get' . $name)) {\n            throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);\n        }\n    }\n\n    /**\n     * Calls the named method which is not a class method.\n     *\n     * Do not call this method directly as it is a PHP magic method that\n     * will be implicitly called when an unknown method is being invoked.\n     * @param string $name the method name\n     * @param array $params method parameters\n     * @throws UnknownMethodException when calling unknown method\n     * @return mixed the method return value\n     */\n    public function __call($name, $params)\n    {\n        throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . \"::$name()\");\n    }\n\n    /**\n     * Returns a value indicating whether a property is defined.\n     *\n     * A property is defined if:\n     *\n     * - the class has a getter or setter method associated with the specified name\n     *   (in this case, property name is case-insensitive);\n     * - the class has a member variable with the specified name (when `$checkVars` is true);\n     *\n     * @param string $name the property name\n     * @param bool $checkVars whether to treat member variables as properties\n     * @return bool whether the property is defined\n     * @see canGetProperty()\n     * @see canSetProperty()\n     */\n    public function hasProperty($name, $checkVars = true)","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/base/BaseObject.php#L205-L241","documentation":"When a method call finds no real method on a yii\\base\\BaseObject subclass, __call() throws UnknownMethodException('Calling unknown method: C::name()') unconditionally - at this base level there is no fallback (only Component adds behavior dispatch). It means the method name is wrong, or the method lives on another class or on a behavior that the plain BaseObject does not support.","triggerScenarios":"Typos ($model->savve()); calling a method that exists on a related class (Query vs ActiveQuery) or on a behavior while the object is a plain BaseObject; methods removed or renamed between Yii 2.0.x releases; dynamic dispatch built from string method names.","commonSituations":"Version drift after composer updates; refactor drift between classes with similar APIs; string-built method names from user input or config.","solutions":["Open the class named in the message and find the real method name (IDE go-to-definition on properly typed variables)","If the method belongs to a related object, call it there, following the object chain the docs use","For optional features guard the call with $obj->hasMethod($name) first"],"exampleFix":"// before\n$users = User::find()->whre(['status' => 1])->all();\n\n// after\n$users = User::find()->where(['status' => 1])->all();","handlingStrategy":"type-guard","validationCode":"if ($object->hasMethod($method)) {\n    $result = $object->$method($args);\n} else {\n    throw new \\BadMethodCallException(get_class($object) . \"::{$method}() does not exist\");\n}","typeGuard":"function supportsMethod(\\yii\\base\\BaseObject $object, string $method): bool\n{\n    return $object->hasMethod($method);\n}","tryCatchPattern":"try {\n    $result = $object->$method();\n} catch (\\yii\\base\\UnknownMethodException $e) {\n    Yii::warning($e->getMessage());\n    $result = $fallback;\n}","preventionTips":["Type-hint variables so unknown methods surface as static-analysis errors","For string-built method names, whitelist them against hasMethod()","After upgrades, grep for removed/renamed methods listed in the CHANGELOG"],"tags":["oop","magic-methods","method-call","typo"],"backgroundTag":"undefined-method-call","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}