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()); + } }