diff --git a/src/Utils/Reflection.php b/src/Utils/Reflection.php index 5e43db2eb..14e58c7a5 100644 --- a/src/Utils/Reflection.php +++ b/src/Utils/Reflection.php @@ -100,7 +100,9 @@ public static function getParameterDefaultValue(\ReflectionParameter $param) public static function getPropertyDeclaringClass(\ReflectionProperty $prop): \ReflectionClass { foreach ($prop->getDeclaringClass()->getTraits() as $trait) { - if ($trait->hasProperty($prop->getName())) { + if ($trait->hasProperty($prop->getName()) + && $trait->getProperty($prop->getName())->getDocComment() === $prop->getDocComment() + ) { return self::getPropertyDeclaringClass($trait->getProperty($prop->getName())); } } diff --git a/tests/Utils/Reflection.getPropertyDeclaringClass.overwrite.phpt b/tests/Utils/Reflection.getPropertyDeclaringClass.overwrite.phpt new file mode 100644 index 000000000..80bf78c2c --- /dev/null +++ b/tests/Utils/Reflection.getPropertyDeclaringClass.overwrite.phpt @@ -0,0 +1,51 @@ +getName()); + +// Property in class - wrong, but impossible to solve in PHP https://github.com/nette/di/issues/169 +Assert::same('A', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('C', 'foo'))->getName()); + +// Property in trait - wrong, but impossible to solve in PHP https://github.com/nette/di/issues/169 +Assert::same('A', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('B', 'foo'))->getName()); + +// Property in trait +Assert::same('A', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('A', 'foo'))->getName()); diff --git a/tests/Utils/Reflection.getPropertyDeclaringClass.overwrite2.phpt b/tests/Utils/Reflection.getPropertyDeclaringClass.overwrite2.phpt new file mode 100644 index 000000000..f4f30e9b6 --- /dev/null +++ b/tests/Utils/Reflection.getPropertyDeclaringClass.overwrite2.phpt @@ -0,0 +1,55 @@ +getName()); + +// Property in class +Assert::same('C', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('C', 'foo'))->getName()); + +// Property in trait +Assert::same('B', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('B', 'foo'))->getName()); + +// Property in trait +Assert::same('A', Reflection::getPropertyDeclaringClass(new \ReflectionProperty('A', 'foo'))->getName());