Skip to content

Commit d548955

Browse files
bug #45981 [Serializer][PropertyInfo] Fix support for "false" built-in type on PHP 8.2 (alexandre-daubois)
This PR was merged into the 4.4 branch. Discussion ---------- [Serializer][PropertyInfo] Fix support for "false" built-in type on PHP 8.2 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes (new language feature support) | New feature? | no | Deprecations? | no | Tickets | _NA_ | License | MIT | Doc PR | _NA_ `false` and `null` built-in types have been merged in PHP 8.2 a few hours ago: php/php-src#7546 🎉 RFC: https://wiki.php.net/rfc/null-false-standalone-types PropertyInfo and Serializer both need an update to support them. Commits ------- 4187d3fddd [Serializer][PropertyInfo] Fix support for "false" built-in type on PHP 8.2
2 parents 15e4f45 + fae5876 commit d548955

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Normalizer/AbstractObjectNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
483483
return (float) $data;
484484
}
485485

486-
if (('is_'.$builtinType)($data)) {
486+
if ('false' === $builtinType || ('is_'.$builtinType)($data)) {
487487
return $data;
488488
}
489489
} catch (NotNormalizableValueException $e) {

Tests/Fixtures/FalseBuiltInDummy.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
class FalseBuiltInDummy
15+
{
16+
public false $false = false;
17+
}

Tests/SerializerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface;
5252
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne;
5353
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo;
54+
use Symfony\Component\Serializer\Tests\Fixtures\FalseBuiltInDummy;
5455
use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy;
5556
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
5657
use Symfony\Component\Serializer\Tests\Normalizer\TestDenormalizer;
@@ -572,6 +573,19 @@ public function testUnionTypeDeserializable()
572573
$this->assertEquals(new DummyUnionType(), $actual, 'Union type denormalization third case failed.');
573574
}
574575

576+
/**
577+
* @requires PHP 8.2
578+
*/
579+
public function testFalseBuiltInTypes()
580+
{
581+
$extractor = new PropertyInfoExtractor([], [new ReflectionExtractor()]);
582+
$serializer = new Serializer([new ObjectNormalizer(null, null, null, $extractor)], ['json' => new JsonEncoder()]);
583+
584+
$actual = $serializer->deserialize('{"false":false}', FalseBuiltInDummy::class, 'json');
585+
586+
$this->assertEquals(new FalseBuiltInDummy(), $actual);
587+
}
588+
575589
private function serializerWithClassDiscriminator()
576590
{
577591
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));

0 commit comments

Comments
 (0)