Skip to content

Commit e20479e

Browse files
committed
Fix calling scope detection inside magic accessors
1 parent d5f4cf2 commit e20479e

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

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

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy;
4+
5+
class TestOverwritePropClass extends FinalPublicClass
6+
{
7+
public function __construct(
8+
protected string $dep,
9+
protected int $count
10+
) {
11+
}
12+
13+
public function getDep(): string
14+
{
15+
return $this->dep;
16+
}
17+
}

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

@@ -190,6 +191,14 @@ public function testFinalPublicClass()
190191
$this->assertSame(1, $proxy->decrement());
191192
}
192193

194+
public function testOverwritePropClass()
195+
{
196+
$proxy = $this->createLazyProxy(TestOverwritePropClass::class, fn () => new TestOverwritePropClass('123', 5));
197+
198+
$this->assertSame('123', $proxy->getDep());
199+
$this->assertSame(1, $proxy->increment());
200+
}
201+
193202
public function testWither()
194203
{
195204
$obj = new class() {

0 commit comments

Comments
 (0)
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