Skip to content

Commit

Permalink
Reflection::getParameterDefaultValue() supports parent::CONST [Closes n…
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 9, 2020
1 parent e05fca8 commit 66d92af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/Utils/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ public static function getParameterDefaultValue(\ReflectionParameter $param)
$const = $orig = $param->getDefaultValueConstantName();
$pair = explode('::', $const);
if (isset($pair[1])) {
if (strtolower($pair[0]) === 'self') {
$pair[0] = $param->getDeclaringClass()->getName();
}
$pair[0] = self::normalizeType($pair[0], $param);
try {
$rcc = new \ReflectionClassConstant($pair[0], $pair[1]);
} catch (\ReflectionException $e) {
Expand Down
2 changes: 2 additions & 0 deletions tests/Utils/Reflection.getParameterDefaultValue.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter

Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'h')));

Assert::same('xyz', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'p')));

Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'i'));
}, ReflectionException::class, 'Unable to resolve constant self::UNDEFINED used as default value of $i in NS\Foo::method().');
Expand Down
10 changes: 8 additions & 2 deletions tests/Utils/fixtures.reflection/defaultValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ interface Bar
const DEFINED = 'xyz';
}

class Foo
class ParentFoo
{
public const PUBLIC_DEFINED = 'xyz';
}

class Foo extends ParentFoo
{
public const PUBLIC_DEFINED = 'abc';
protected const PROTECTED_DEFINED = 'abc';
Expand All @@ -35,7 +40,8 @@ public function method(
$l = Undefined::ANY,
$m = DEFINED,
$n = UNDEFINED,
$o = NS_DEFINED
$o = NS_DEFINED,
$p = parent::PUBLIC_DEFINED
) {
}
}

0 comments on commit 66d92af

Please sign in to comment.