diff --git a/src/Persistence/Reflection/RuntimeReflectionProperty.php b/src/Persistence/Reflection/RuntimeReflectionProperty.php index 595ffc74..6c53f8df 100644 --- a/src/Persistence/Reflection/RuntimeReflectionProperty.php +++ b/src/Persistence/Reflection/RuntimeReflectionProperty.php @@ -9,6 +9,7 @@ use ReflectionProperty; use ReturnTypeWillChange; +use function ltrim; use function method_exists; /** @@ -26,7 +27,7 @@ public function __construct(string $class, string $name) { parent::__construct($class, $name); - $this->key = $this->isPrivate() ? "\0" . $class . "\0" . $name : ($this->isProtected() ? "\0*\0" . $name : $name); + $this->key = $this->isPrivate() ? "\0" . ltrim($class, '\\') . "\0" . $name : ($this->isProtected() ? "\0*\0" . $name : $name); } /** diff --git a/tests/Persistence/RuntimeReflectionPropertyTest.php b/tests/Persistence/RuntimeReflectionPropertyTest.php index 6733f166..606163a3 100644 --- a/tests/Persistence/RuntimeReflectionPropertyTest.php +++ b/tests/Persistence/RuntimeReflectionPropertyTest.php @@ -36,6 +36,7 @@ public function testGetSetValue(string $name, string $value): void self::assertSame($value, $reflProperty->getValue($object)); + $reflProperty->setAccessible(true); $reflProperty->setValue($object, 'changedValue'); self::assertSame('changedValue', $reflProperty->getValue($object)); @@ -46,6 +47,7 @@ public function testGetSetValue(string $name, string $value): void * * @testWith ["Doctrine\\Tests\\Persistence\\RuntimeReflectionPropertyTestProxyMock"] * ["Doctrine\\Tests\\Persistence\\RuntimeReflectionPropertyTestCommonProxyMock"] + * ["\\Doctrine\\Tests\\Persistence\\RuntimeReflectionPropertyTestProxyMock"] */ public function testGetValueOnProxyProperty(string $proxyClass): void { @@ -245,5 +247,10 @@ class RuntimeReflectionPropertyTestClass public $test = 'testValue'; /** @var string|null */ - public $privateTest = 'privateTestValue'; + private $privateTest = 'privateTestValue'; + + public function getPrivateTest(): ?string + { + return $this->privateTest; + } }