{"record":{"id":"2595e8bd682bec7d","repo":"octobercms/october","slug":"class-class-must-define-property-property-used-2595e8","errorCode":null,"errorMessage":"Class :class must define property $:property used by :behavior behavior.","messagePattern":"Class :class must define property \\$:property used by :behavior behavior\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":500,"severity":"error","filePath":"modules/system/classes/ModelBehavior.php","lineNumber":32,"sourceCode":"{\n    /**\n     * @var array requiredProperties that must exist in the model using this behavior.\n     */\n    protected $requiredProperties = [];\n\n    /**\n     * __construct\n     * @param \\October\\Rain\\Database\\Model $model The extended model.\n     * @throws ApplicationException\n     */\n    public function __construct($model)\n    {\n        parent::__construct($model);\n\n        // Validate model properties\n        foreach ($this->requiredProperties as $property) {\n            if (!isset($model->{$property})) {\n                throw new ApplicationException(Lang::get('system::lang.behavior.missing_property', [\n                    'class' => get_class($model),\n                    'property' => $property,\n                    'behavior' => get_called_class()\n                ]));\n            }\n        }\n    }\n}\n","sourceCodeStart":14,"sourceCodeEnd":41,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/system/classes/ModelBehavior.php#L14-L41","documentation":"ModelBehavior is the base class for model behaviors attached via public $implement (e.g. System\\Behaviors\\SettingsModel). Its constructor iterates $requiredProperties and checks each against the host model instance with isset(); any missing property throws ApplicationException with the lang key system::lang.behavior.missing_property, naming the model class, the property, and the behavior. SettingsModel for example requires $settingsFields and $settingsCode on the model.","triggerScenarios":"Declaring public $implement = ['System.Behaviors.SettingsModel']; on a model without also declaring public $settingsCode = 'acme.blog.settings'; and public $settingsFields = 'settings.yaml';; attaching any custom behavior that sets $requiredProperties to a model lacking those public properties.","commonSituations":"First-time settings-model setup following docs partially; refactoring a settings model and dropping a property; custom behaviors written by plugin authors who list required config keys the consumer forgot; property declared but not public (protected visibility fails isset($model->...) from outside).","solutions":["Add the missing public property to the model class — the message names exactly which property and which behavior demanded it.","Ensure the property is public and spelled exactly as required (e.g. $settingsCode, $settingsFields for SettingsModel).","For your own behaviors, review requiredProperties and declare each listed key on the consuming model."],"exampleFix":"// before\nclass Settings extends Model\n{\n    public $implement = ['System.Behaviors.SettingsModel'];\n}\n\n// after\nclass Settings extends Model\n{\n    public $implement = ['System.Behaviors.SettingsModel'];\n    public $settingsCode = 'acme.blog.settings';\n    public $settingsFields = 'settings.yaml';\n}","handlingStrategy":"validation","validationCode":"// Before attaching a behavior, confirm the model defines every required property\nfunction behaviorRequirementsMet(string $modelClass, array $requiredProperties): bool\n{\n    foreach ($requiredProperties as $property) {\n        if (!property_exists($modelClass, $property)) {\n            return false;\n        }\n    }\n    return true;\n}","typeGuard":"function hasSettingsBehaviorConfig(string $modelClass): bool\n{\n    return property_exists($modelClass, 'settingsCode')\n        && property_exists($modelClass, 'settingsFields');\n}","tryCatchPattern":"try {\n    $model->addBehavior(System\\Behaviors\\SettingsModel::class);\n} catch (\\October\\Rain\\Exception\\ApplicationException $e) {\n    // surface to the developer at boot, not at request time\n    throw new RuntimeException('Settings model misconfigured: ' . $e->getMessage(), 0, $e);\n}","preventionTips":["Declare required behavior properties as public on the model ($settingsCode, $settingsFields for SettingsModel).","Add a boot-time assertion in plugin tests that instantiates every implemented model and behavior pair.","Read the error text — it names the exact class, property, and behavior."],"tags":["php","model","behavior","settings-model","missing-property"],"backgroundTag":"missing-required-property","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}