Skip to content

Commit

Permalink
Fix support for ::class magic constant in sudo and reflecting comma…
Browse files Browse the repository at this point in the history
…nds (doc, ls, etc)

Fixes #783
  • Loading branch information
bobthecow committed Apr 2, 2024
1 parent 99579f8 commit ab3316c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Sudo.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public static function fetchClassConst($class, string $const)
{
$refl = new \ReflectionClass($class);

// Special case the ::class magic constant, because `getConstant` does the wrong thing here.
if ($const === 'class') {
return $refl->getName();
}

do {
if ($refl->hasConstant($const)) {
return $refl->getConstant($const);
Expand Down
1 change: 1 addition & 0 deletions test/SudoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function testFetchClassConst()
{
$obj = new ClassWithSecrets();
$this->assertSame('private and const', Sudo::fetchClassConst($obj, 'PRIVATE_CONST'));
$this->assertSame(ClassWithSecrets::class, Sudo::fetchClassConst($obj, 'class'));
}

public function testParentProperties()
Expand Down

0 comments on commit ab3316c

Please sign in to comment.