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

Commit1edecf7

Browse files
greedyivanfabpot
authored andcommitted
[Validator] fix access to uninitialized property when getting value
1 parente50db1f commit1edecf7

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

‎src/Symfony/Component/Validator/Mapping/PropertyMetadata.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ public function __construct($class, $name)
4848
*/
4949
publicfunctiongetPropertyValue($object)
5050
{
51-
return$this->getReflectionMember($object)->getValue($object);
51+
$reflProperty =$this->getReflectionMember($object);
52+
53+
if (\PHP_VERSION_ID >=70400 && !$reflProperty->isInitialized($object)) {
54+
returnnull;
55+
}
56+
57+
return$reflProperty->getValue($object);
5258
}
5359

5460
/**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespaceSymfony\Component\Validator\Tests\Fixtures;
4+
5+
class Entity_74
6+
{
7+
publicint$uninitialized;
8+
}

‎src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
usePHPUnit\Framework\TestCase;
1515
useSymfony\Component\Validator\Mapping\PropertyMetadata;
1616
useSymfony\Component\Validator\Tests\Fixtures\Entity;
17+
useSymfony\Component\Validator\Tests\Fixtures\Entity_74;
1718

1819
class PropertyMetadataTestextends TestCase
1920
{
2021
constCLASSNAME ='Symfony\Component\Validator\Tests\Fixtures\Entity';
22+
constCLASSNAME_74 ='Symfony\Component\Validator\Tests\Fixtures\Entity_74';
2123
constPARENTCLASS ='Symfony\Component\Validator\Tests\Fixtures\EntityParent';
2224

2325
publicfunctiontestInvalidPropertyName()
@@ -53,4 +55,15 @@ public function testGetPropertyValueFromRemovedProperty()
5355
$this->expectException('Symfony\Component\Validator\Exception\ValidatorException');
5456
$metadata->getPropertyValue($entity);
5557
}
58+
59+
/**
60+
* @requires PHP 7.4
61+
*/
62+
publicfunctiontestGetPropertyValueFromUninitializedProperty()
63+
{
64+
$entity =newEntity_74();
65+
$metadata =newPropertyMetadata(self::CLASSNAME_74,'uninitialized');
66+
67+
$this->assertNull($metadata->getPropertyValue($entity));
68+
}
5669
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp