Skip to content

Commit a7e10fc

Browse files
committed
Added support for PHP 7.4 to PropertyNormalizer
1 parent 3b42ca9 commit a7e10fc

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ protected function getAttributeValue($object, $attribute, $format = null, array
124124
return null;
125125
}
126126

127+
if (\PHP_VERSION_ID >= 70400 && !$reflectionProperty->isInitialized($object)) {
128+
return null;
129+
}
130+
127131
// Override visibility
128132
if (!$reflectionProperty->isPublic()) {
129133
$reflectionProperty->setAccessible(true);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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\Serializer\Tests\Fixtures;
13+
14+
/**
15+
* @author Valentin Udaltsov <udaltsov.valentin@gmail.com>
16+
*/
17+
final class Php74Dummy
18+
{
19+
public string $property;
20+
}

src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy;
2323
use Symfony\Component\Serializer\Tests\Fixtures\GroupDummyChild;
2424
use Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy;
25+
use Symfony\Component\Serializer\Tests\Fixtures\Php74Dummy;
2526
use Symfony\Component\Serializer\Tests\Fixtures\PropertyCircularReferenceDummy;
2627
use Symfony\Component\Serializer\Tests\Fixtures\PropertySiblingHolder;
2728

@@ -55,6 +56,18 @@ public function testNormalize()
5556
);
5657
}
5758

59+
/**
60+
* @requires PHP 7.4
61+
*/
62+
public function testNormalizeUninitializedProperty()
63+
{
64+
$obj = new Php74Dummy();
65+
$this->assertEquals(
66+
['property' => null],
67+
$this->normalizer->normalize($obj, 'any')
68+
);
69+
}
70+
5871
public function testDenormalize()
5972
{
6073
$obj = $this->normalizer->denormalize(

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