diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 5117c60c6a2..bf70d2c797f 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -7,6 +7,7 @@ Yii Framework 2 Change Log - Bug #19243: Handle `finfo_open` for tar.xz as `application/octet-stream` on PHP 8.1 (longthanhtran) - Bug #19235: Fix return type compatibility of `yii\web\SessionIterator` class methods for PHP 8.1 (virtual-designer) - Bug #19291: Reset errors and validators in `yii\base\Model::__clone()` (WinterSilence) +- Enh #19309: Optimize `yii\base\Model::attributes()` (WinterSilence) 2.0.45 February 11, 2022 diff --git a/framework/base/Model.php b/framework/base/Model.php index 900bb0c610b..74f8da35aba 100644 --- a/framework/base/Model.php +++ b/framework/base/Model.php @@ -260,21 +260,15 @@ public function formName() /** * Returns the list of attribute names. + * * By default, this method returns all public non-static properties of the class. * You may override this method to change the default behavior. - * @return array list of attribute names. + * + * @return string[] list of attribute names. */ public function attributes() { - $class = new ReflectionClass($this); - $names = []; - foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { - if (!$property->isStatic()) { - $names[] = $property->getName(); - } - } - - return $names; + return array_keys(Yii::getObjectVars($this)); } /**