Skip to content

Commit 520e31b

Browse files
bug #58959 [PropertyInfo] consider write property visibility to decide whether a property is writable (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [PropertyInfo] consider write property visibility to decide whether a property is writable | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | part of #58556 | License | MIT Commits ------- 49126e1 consider write property visibility to decide whether a property is writable
2 parents 5cbdb87 + 49126e1 commit 520e31b

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 testAsymmetricVisibility()
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