Skip to content

Commit 41e3615

Browse files
vtsykunnicolas-grekas
authored andcommitted
[VarDumper] Fix calling scope detection inside magic accessors
1 parent 1307d87 commit 41e3615

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static function getScope($propertyScopes, $class, $property, $readonlySco
141141
if (\ReflectionProperty::class === $scope = $frame['class'] ?? \Closure::class) {
142142
$scope = $frame['object']->class;
143143
}
144-
if (null === $readonlyScope && '*' === $k[1] && ($class === $scope || is_subclass_of($class, $scope))) {
144+
if (null === $readonlyScope && '*' === $k[1] && ($class === $scope || (is_subclass_of($class, $scope) && !isset($propertyScopes["\0$scope\0$property"])))) {
145145
return null;
146146
}
147147

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy;
13+
14+
class TestOverwritePropClass extends FinalPublicClass
15+
{
16+
public function __construct(
17+
protected string $dep,
18+
protected int $count,
19+
) {
20+
}
21+
22+
public function getDep(): string
23+
{
24+
return $this->dep;
25+
}
26+
}

src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\ReadOnlyClass;
2020
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\StringMagicGetClass;
2121
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestClass;
22+
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestOverwritePropClass;
2223
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestUnserializeClass;
2324
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestWakeupClass;
2425

@@ -194,6 +195,14 @@ public function testFinalPublicClass()
194195
$this->assertSame(1, $proxy->decrement());
195196
}
196197

198+
public function testOverwritePropClass()
199+
{
200+
$proxy = $this->createLazyProxy(TestOverwritePropClass::class, fn () => new TestOverwritePropClass('123', 5));
201+
202+
$this->assertSame('123', $proxy->getDep());
203+
$this->assertSame(1, $proxy->increment());
204+
}
205+
197206
public function testWither()
198207
{
199208
$obj = new class() {

0 commit comments

Comments
 (0)