yiisoft/yii2 · error · UnknownPropertyException
Setting unknown property: {class}::{name}
Error message
Setting unknown property: {class}::{name} What it means
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.
Source
Thrown at framework/base/BaseObject.php:164
* Sets value of an object property.
*
* Do not call this method directly as it is a PHP magic method that
* will be implicitly called when executing `$object->property = $value;`.
* @param string $name the property name or the event name
* @param mixed $value the property value
* @throws UnknownPropertyException if the property is not defined
* @throws InvalidCallException if the property is read-only
* @see __get()
*/
public function __set($name, $value)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
} else {
throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}
}
/**
* Checks if a property is set, i.e. defined and not null.
*
* Do not call this method directly as it is a PHP magic method that
* will be implicitly called when executing `isset($object->property)`.
*
* Note that if the property is not defined, false will be returned.
* @param string $name the property name or the event name
* @return bool whether the named property is set (not null).
* @see https://www.php.net/manual/en/function.isset.php
*/
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {View on GitHub (pinned to 66f00d18a2)
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
Example fix
// before
'components' => [
'cache' => ['class' => \yii\caching\DbCache::class, 'cacheTabl' => 'cache'],
],
// after
'components' => [
'cache' => ['class' => \yii\caching\DbCache::class, 'cacheTable' => 'cache'],
], Defensive patterns
Strategy: type-guard
Validate before calling
foreach ($config as $key => $value) {
if (strncmp($key, 'on ', 3) !== 0 && strncmp($key, 'as ', 3) !== 0
&& !$object->canSetProperty($key) && !isset($object->$key)) {
unset($config[$key]); // or throw with the key name
}
} Type guard
function isWritableConfigKey(\yii\base\BaseObject $object, string $key): bool
{
return strncmp($key, 'on ', 3) === 0
|| strncmp($key, 'as ', 3) === 0
|| $object->canSetProperty($key);
} Try / catch
try {
Yii::configure($object, $config);
} catch (\yii\base\UnknownPropertyException $e) {
Yii::error('Config key rejected: ' . $e->getMessage());
throw $e;
} Prevention
- 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
When it happens
Trigger: '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.
Common situations: 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.
Related errors
- Getting unknown property: {class}::{name}
- Calling unknown method: {class}::{name}()
- 'Getting write-only property: ' . get_class($this) . '::' .
- Setting read-only property: {class}::{name}
- Unsetting read-only property: {class}::{name}
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/1c81d16fef52de5b.
Report an issue: GitHub.