From 726e6416cb622b2d024973bb0baeaa9a69fe8dad Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 22 Sep 2023 18:59:21 -0300 Subject: [PATCH] Add method `className()`, don't break BC third party extensions. --- framework/base/BaseObject.php | 10 ++++++++++ tests/framework/base/BaseObjectTest.php | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/framework/base/BaseObject.php b/framework/base/BaseObject.php index 2f9448efc17..84e88730485 100644 --- a/framework/base/BaseObject.php +++ b/framework/base/BaseObject.php @@ -282,4 +282,14 @@ public function hasMethod($name) { return method_exists($this, $name); } + + /** + * Returns the fully qualified name of this class. + * + * @return string the fully qualified name of this class. + */ + public static function className(): string + { + return static::class; + } } diff --git a/tests/framework/base/BaseObjectTest.php b/tests/framework/base/BaseObjectTest.php index a35603f3cd6..eea3725518b 100644 --- a/tests/framework/base/BaseObjectTest.php +++ b/tests/framework/base/BaseObjectTest.php @@ -159,6 +159,11 @@ public function testReadingWriteOnlyProperty() $this->expectExceptionMessage('Getting write-only property: yiiunit\framework\base\NewObject::writeOnly'); $this->object->writeOnly; } + + public function testClassName(): void + { + $this->assertSame(NewObject::class, $this->object::className()); + } }