From c13f34628c6e7633bab9dedbc915468e49dd397e Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 16 Mar 2022 23:05:37 +0300 Subject: [PATCH 1/2] Optimize Model::attributes() --- framework/base/Model.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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)); } /** From 32f79bca0bdb4251ed8bb09225eeaf63406b31a4 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 17 Mar 2022 22:08:17 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- framework/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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