Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf06b842

Browse files
committed
a readonly property must not be reported as being writable
1 parentc959125 commitf06b842

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function isReadable($class, $property, array $context = []): ?bool
180180
*/
181181
publicfunctionisWritable($class,$property,array$context = []): ?bool
182182
{
183-
if ($this->isAllowedProperty($class,$property)) {
183+
if ($this->isAllowedProperty($class,$property,true)) {
184184
returntrue;
185185
}
186186

@@ -389,11 +389,15 @@ private function isNullableProperty(string $class, string $property): bool
389389
returnfalse;
390390
}
391391

392-
privatefunctionisAllowedProperty(string$class,string$property):bool
392+
privatefunctionisAllowedProperty(string$class,string$property,bool$writeAccessRequired =false):bool
393393
{
394394
try {
395395
$reflectionProperty =new \ReflectionProperty($class,$property);
396396

397+
if (\PHP_VERSION_ID >=80100 &&$writeAccessRequired &&$reflectionProperty->isReadOnly()) {
398+
returnfalse;
399+
}
400+
397401
if ($this->accessFlags &self::ALLOW_PUBLIC &&$reflectionProperty->isPublic()) {
398402
returntrue;
399403
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
useSymfony\Component\PropertyInfo\Tests\Fixtures\Php74Dummy;
2323
useSymfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy;
2424
useSymfony\Component\PropertyInfo\Tests\Fixtures\Php7ParentDummy;
25+
useSymfony\Component\PropertyInfo\Tests\Fixtures\Php81Dummy;
2526
useSymfony\Component\PropertyInfo\Type;
2627

2728
/**
@@ -234,6 +235,7 @@ public function php71TypesProvider()
234235

235236
/**
236237
* @dataProvider php80TypesProvider
238+
*
237239
* @requires PHP 8
238240
*/
239241
publicfunctiontestExtractPhp80Type($property,array$type =null)
@@ -257,6 +259,7 @@ public function php80TypesProvider()
257259

258260
/**
259261
* @dataProvider php81TypesProvider
262+
*
260263
* @requires PHP 8.1
261264
*/
262265
publicfunctiontestExtractPhp81Type($property,array$type =null)
@@ -272,8 +275,17 @@ public function php81TypesProvider()
272275
];
273276
}
274277

278+
/**
279+
* @requires PHP 8.1
280+
*/
281+
publicfunctiontestReadonlyPropertiesAreNotWriteable()
282+
{
283+
$this->assertFalse($this->extractor->isWritable(Php81Dummy::class,'foo'));
284+
}
285+
275286
/**
276287
* @dataProvider php82TypesProvider
288+
*
277289
* @requires PHP 8.2
278290
*/
279291
publicfunctiontestExtractPhp82Type($property,array$type =null)

‎src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
class Php81Dummy
1515
{
16+
publicfunction__construct(publicreadonlystring$foo)
17+
{
18+
}
19+
1620
publicfunctiongetNothing(): never
1721
{
1822
thrownew \Exception('Oops');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp