From 41e36157b760e8252abbf3c7deb930819be3bf1e Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Tue, 25 Jul 2023 05:39:32 +0200 Subject: [PATCH] [VarDumper] Fix calling scope detection inside magic accessors --- .../Internal/LazyObjectRegistry.php | 2 +- .../LazyProxy/TestOverwritePropClass.php | 26 +++++++++++++++++++ .../VarExporter/Tests/LazyProxyTraitTest.php | 9 +++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/TestOverwritePropClass.php 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() { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy