Skip to content

Commit 30f70aa

Browse files
committed
consider write property visibility to decide whether a property is writable
1 parent 85419bc commit 30f70aa

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,10 @@ private function isAllowedProperty(string $class, string $property, bool $writeA
621621
return false;
622622
}
623623

624+
if (\PHP_VERSION_ID >= 80400 && $writeAccessRequired && ($reflectionProperty->isProtectedSet() || $reflectionProperty->isPrivateSet())) {
625+
return false;
626+
}
627+
624628
return (bool) ($reflectionProperty->getModifiers() & $this->propertyReflectionFlags);
625629
} catch (\ReflectionException $e) {
626630
// Return false if the property doesn't exist

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\PropertyInfo\PropertyReadInfo;
1818
use Symfony\Component\PropertyInfo\PropertyWriteInfo;
1919
use Symfony\Component\PropertyInfo\Tests\Fixtures\AdderRemoverDummy;
20+
use Symfony\Component\PropertyInfo\Tests\Fixtures\AsymmetricVisibility;
2021
use Symfony\Component\PropertyInfo\Tests\Fixtures\DefaultValue;
2122
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
2223
use Symfony\Component\PropertyInfo\Tests\Fixtures\NotInstantiable;
@@ -685,4 +686,17 @@ public static function extractConstructorTypesProvider(): array
685686
['ddd', null],
686687
];
687688
}
689+
690+
/**
691+
* @requires PHP 8.4
692+
*/
693+
public function testAsymetricVisibility()
694+
{
695+
$this->assertTrue($this->extractor->isReadable(AsymmetricVisibility::class, 'publicPrivate'));
696+
$this->assertTrue($this->extractor->isReadable(AsymmetricVisibility::class, 'publicProtected'));
697+
$this->assertFalse($this->extractor->isReadable(AsymmetricVisibility::class, 'protectedPrivate'));
698+
$this->assertFalse($this->extractor->isWritable(AsymmetricVisibility::class, 'publicPrivate'));
699+
$this->assertFalse($this->extractor->isWritable(AsymmetricVisibility::class, 'publicProtected'));
700+
$this->assertFalse($this->extractor->isWritable(AsymmetricVisibility::class, 'protectedPrivate'));
701+
}
688702
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\PropertyInfo\Tests\Fixtures;
13+
14+
class AsymmetricVisibility
15+
{
16+
public private(set) mixed $publicPrivate;
17+
public protected(set) mixed $publicProtected;
18+
protected private(set) mixed $protectedPrivate;
19+
}

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