{"record":{"id":"1c81d16fef52de5b","repo":"yiisoft/yii2","slug":"setting-unknown-property-class-name","errorCode":null,"errorMessage":"Setting unknown property: {class}::{name}","messagePattern":"Setting unknown property: (.+?)::(.+?)","errorType":"exception","errorClass":"UnknownPropertyException","httpStatus":null,"severity":"error","filePath":"framework/base/BaseObject.php","lineNumber":164,"sourceCode":"     * Sets value of an object property.\n     *\n     * Do not call this method directly as it is a PHP magic method that\n     * will be implicitly called when executing `$object->property = $value;`.\n     * @param string $name the property name or the event name\n     * @param mixed $value the property value\n     * @throws UnknownPropertyException if the property is not defined\n     * @throws InvalidCallException if the property is read-only\n     * @see __get()\n     */\n    public function __set($name, $value)\n    {\n        $setter = 'set' . $name;\n        if (method_exists($this, $setter)) {\n            $this->$setter($value);\n        } elseif (method_exists($this, 'get' . $name)) {\n            throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);\n        } else {\n            throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);\n        }\n    }\n\n    /**\n     * Checks if a property is set, i.e. defined and not null.\n     *\n     * Do not call this method directly as it is a PHP magic method that\n     * will be implicitly called when executing `isset($object->property)`.\n     *\n     * Note that if the property is not defined, false will be returned.\n     * @param string $name the property name or the event name\n     * @return bool whether the named property is set (not null).\n     * @see https://www.php.net/manual/en/function.isset.php\n     */\n    public function __isset($name)\n    {\n        $getter = 'get' . $name;\n        if (method_exists($this, $getter)) {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/base/BaseObject.php#L146-L182","documentation":"The __set() counterpart of the unknown-property read error: assigning to a name that has no setter, no getter, and is not a public member throws UnknownPropertyException('Setting unknown property: C::p'). Because Yii configures objects by assigning each config-array key through __set(), this is the classic symptom of a misspelled or unsupported key in a components/config array - the message names the component class and the offending key.","triggerScenarios":"'components' => ['cache' => ['class' => \\yii\\caching\\DbCache::class, 'cacheTabl' => 'cache']] (typo); using a config option that exists only in a newer 2.0.x release than the one installed; a 'class' key pointing to a different class than you think, so its option keys do not apply; trying to set private or static members via instance syntax.","commonSituations":"Long config files with typos; snippets copied from docs written for another version; extension options renamed between releases; ArrayHelper::merge dropping or relocating nested keys.","solutions":["Compare the failing key (shown in the message) with the class's real property list in its source or @property docblock and fix the spelling","Verify the 'class' value in that config block is really the class you intend to configure","Confirm the installed package version supports the option (composer show) and update, or find the legacy option name"],"exampleFix":"// before\n'components' => [\n    'cache' => ['class' => \\yii\\caching\\DbCache::class, 'cacheTabl' => 'cache'],\n],\n\n// after\n'components' => [\n    'cache' => ['class' => \\yii\\caching\\DbCache::class, 'cacheTable' => 'cache'],\n],","handlingStrategy":"type-guard","validationCode":"foreach ($config as $key => $value) {\n    if (strncmp($key, 'on ', 3) !== 0 && strncmp($key, 'as ', 3) !== 0\n        && !$object->canSetProperty($key) && !isset($object->$key)) {\n        unset($config[$key]); // or throw with the key name\n    }\n}","typeGuard":"function isWritableConfigKey(\\yii\\base\\BaseObject $object, string $key): bool\n{\n    return strncmp($key, 'on ', 3) === 0\n        || strncmp($key, 'as ', 3) === 0\n        || $object->canSetProperty($key);\n}","tryCatchPattern":"try {\n    Yii::configure($object, $config);\n} catch (\\yii\\base\\UnknownPropertyException $e) {\n    Yii::error('Config key rejected: ' . $e->getMessage());\n    throw $e;\n}","preventionTips":["Let the IDE autocomplete config keys from the class's @property annotations","Pin and review package versions so copied config snippets match the installed API","Validate merged config arrays against the target class in unit tests"],"tags":["oop","magic-methods","configuration","typo"],"backgroundTag":"undefined-property-write","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}