{"record":{"id":"fdcb0807bd348bc1","repo":"yiisoft/yii2","slug":"getting-unknown-property-class-name","errorCode":null,"errorMessage":"Getting unknown property: {class}::{name}","messagePattern":"Getting unknown property: (.+?)::(.+?)","errorType":"exception","errorClass":"UnknownPropertyException","httpStatus":null,"severity":"error","filePath":"framework/base/BaseObject.php","lineNumber":142,"sourceCode":"     *\n     * Do not call this method directly as it is a PHP magic method that\n     * will be implicitly called when executing `$value = $object->property;`.\n     * @param string $name the property name\n     * @return mixed the property value\n     * @throws UnknownPropertyException if the property is not defined\n     * @throws InvalidCallException if the property is write-only\n     * @see __set()\n     */\n    public function __get($name)\n    {\n        $getter = 'get' . $name;\n        if (method_exists($this, $getter)) {\n            return $this->$getter();\n        } elseif (method_exists($this, 'set' . $name)) {\n            throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);\n        }\n\n        throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);\n    }\n\n    /**\n     * 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);","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/base/BaseObject.php#L124-L160","documentation":"BaseObject::__get() throws UnknownPropertyException('Getting unknown property: C::p') when the accessed name has no getter, no setter, and is not a public member variable - that property simply does not exist on the object. The message names the concrete class, so check exactly that class's property list; magic properties are documented via @property annotations in the class docblock.","triggerScenarios":"Typo on a read path ($user->emial); reading a property that exists only on a subclass while the variable holds a base-class or sibling instance; accessing a protected/private member from outside; reading a magic property that the installed package version does not have yet (added in a later release).","commonSituations":"Version drift after composer update or downgrade (properties renamed or moved between classes); templates and generic loops reading object fields dynamically; refactors that moved a getter to a helper class.","solutions":["Fix the property name against the class's @property annotations or getter list","If the value may be absent, guard the read with $object->canGetProperty($name) or isset($object->$name)","If the property should exist on your class, add the getter or a public field","Check the installed version (composer show vendor/package) against the docs you followed"],"exampleFix":"// before\n$email = $user->emial; // typo\n\n// after\n$email = $user->email;","handlingStrategy":"type-guard","validationCode":"if ($model->canGetProperty('email')) {\n    $email = $model->email;\n} else {\n    $email = ''; // property absent on this object/version\n}","typeGuard":"function canRead(\\yii\\base\\BaseObject $object, string $name): bool\n{\n    return isset($object->$name) || $object->canGetProperty($name);\n}","tryCatchPattern":"try {\n    $value = $object->$name;\n} catch (\\yii\\base\\UnknownPropertyException $e) {\n    // message names the class and the missing property\n    Yii::warning($e->getMessage());\n    $value = $default;\n}","preventionTips":["Type-hint variables properly so IDEs catch misspelled property reads statically","Read @property annotations of the class before dynamic access","After composer updates, grep code for properties mentioned in the CHANGELOG as renamed or removed"],"tags":["oop","magic-methods","property-access","typo"],"backgroundTag":"undefined-property-read","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}