Skip to content

Commit fad0292

Browse files
committed
Support using class references in form of strings for package()
1 parent c8d44ff commit fad0292

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/main/php/lang/Reflection.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public static function package($arg) {
7878
$name= strtr($arg, '\\', '.');
7979
if ($cl->providesPackage($name)) {
8080
return new Package($name);
81+
} else if ($cl->providesClass($name)) {
82+
return new Package(substr($name, 0, strrpos($name, '.')));
8183
}
8284
throw new IllegalArgumentException('No package named '.$name);
8385
}

src/test/php/lang/reflection/unittest/ReflectionTest.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ private function arguments() {
2323
private function packages() {
2424
yield [__NAMESPACE__, 'namespace literal'];
2525
yield ['lang.reflection.unittest', 'namespace name'];
26+
yield [self::class, 'class literal'];
27+
yield [nameof($this), 'class name'];
2628
yield [$this, 'instance'];
2729
yield [Type::forName(self::class), 'type'];
2830
yield [Reflection::of(self::class), 'reflection'];

0 commit comments

Comments
 (0)