diff --git a/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php b/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php index c78bdcf510c0b..a73e6bea44c92 100644 --- a/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php +++ b/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php @@ -141,7 +141,7 @@ public static function getScope($propertyScopes, $class, $property, $readonlySco if (\ReflectionProperty::class === $scope = $frame['class'] ?? \Closure::class) { $scope = $frame['object']->class; } - if (null === $readonlyScope && '*' === $k[1] && ($class === $scope || is_subclass_of($class, $scope))) { + if (null === $readonlyScope && '*' === $k[1] && ($class === $scope || (is_subclass_of($class, $scope) && !isset($propertyScopes["\0$scope\0$property"])))) { return null; } diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/TestOverwritePropClass.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/TestOverwritePropClass.php new file mode 100644 index 0000000000000..6a7bd6501d971 --- /dev/null +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/TestOverwritePropClass.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy; + +class TestOverwritePropClass extends FinalPublicClass +{ + public function __construct( + protected string $dep, + protected int $count, + ) { + } + + public function getDep(): string + { + return $this->dep; + } +} diff --git a/src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php b/src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php index 58d49e5aa0404..c56e14ce4566e 100644 --- a/src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php +++ b/src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php @@ -19,6 +19,7 @@ use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\ReadOnlyClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\StringMagicGetClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestClass; +use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestOverwritePropClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestUnserializeClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestWakeupClass; @@ -194,6 +195,14 @@ public function testFinalPublicClass() $this->assertSame(1, $proxy->decrement()); } + public function testOverwritePropClass() + { + $proxy = $this->createLazyProxy(TestOverwritePropClass::class, fn () => new TestOverwritePropClass('123', 5)); + + $this->assertSame('123', $proxy->getDep()); + $this->assertSame(1, $proxy->increment()); + } + public function testWither() { $obj = new class() {