diff --git a/src/Utils/Reflection.php b/src/Utils/Reflection.php index a394fc76c..60b13dda1 100644 --- a/src/Utils/Reflection.php +++ b/src/Utils/Reflection.php @@ -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) { diff --git a/tests/Utils/Reflection.getParameterDefaultValue.phpt b/tests/Utils/Reflection.getParameterDefaultValue.phpt index 8528e001b..8cd5ce437 100644 --- a/tests/Utils/Reflection.getParameterDefaultValue.phpt +++ b/tests/Utils/Reflection.getParameterDefaultValue.phpt @@ -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().'); diff --git a/tests/Utils/fixtures.reflection/defaultValue.php b/tests/Utils/fixtures.reflection/defaultValue.php index 8360879a6..196ab13de 100644 --- a/tests/Utils/fixtures.reflection/defaultValue.php +++ b/tests/Utils/fixtures.reflection/defaultValue.php @@ -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'; @@ -35,7 +40,8 @@ public function method( $l = Undefined::ANY, $m = DEFINED, $n = UNDEFINED, - $o = NS_DEFINED + $o = NS_DEFINED, + $p = parent::PUBLIC_DEFINED ) { } }