Skip to content

Property Access fails on properties with a dot (.) #58100

@evs-xsarus

Description

@evs-xsarus

Symfony version(s) affected

6.4.8 and 7.1.1

Description

When serializing an object which has properties with a dot in the name, a NoSuchPropertyException is thrown.

How to reproduce

Run this on PHP 8.3

composer.json for 6.4.8

{
    "require": {
        "symfony/property-access": "^6",
        "symfony/serializer": "^6",
        "phpdocumentor/reflection-docblock": "^5.4"
    }
}

composer.json for 7.1.1

{
    "require": {
        "symfony/property-access": "^7.1",
        "symfony/serializer": "^7.1",
        "phpdocumentor/reflection-docblock": "^5.4"
    }
}

test.php

<?php
declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

$stdclass = (object) ['bankAccount.iban' => 'NL16TEST0436169118', 'bankSummary' => ''];

$reflectionExtractor   = new ReflectionExtractor();
$phpDocExtractor       = new PhpDocExtractor();
$propertyTypeExtractor = new PropertyInfoExtractor([$reflectionExtractor], [$phpDocExtractor, $reflectionExtractor], [$phpDocExtractor], [$reflectionExtractor], [$reflectionExtractor]);
$normalizers           = [
    new BackedEnumNormalizer(),
    new DateTimeNormalizer([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d\TH:i:sP', DateTimeNormalizer::TIMEZONE_KEY => 'Z']),
    new ArrayDenormalizer(),
    new JsonSerializableNormalizer(),
    new ObjectNormalizer(
        null,
        null,
        null,
        $propertyTypeExtractor,
        null,
        null,
        [
            AbstractObjectNormalizer::SKIP_NULL_VALUES       => true,
            AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => true,
        ]
    ),
];

$encoders = [
    new JsonEncoder(),
];

$serializer = new Serializer($normalizers, $encoders);
$serializer->serialize($stdclass, 'json');

Possible Solution

No response

Additional Context

Fatal error: Uncaught Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException: Can't get a way to read the property "bankAccount" in class "stdClass". in /sites/property-access/vendor/symfony/property-access/PropertyAccessor.php on line 442

Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException: Can't get a way to read the property "bankAccount" in class "stdClass". in /sites/property-access/vendor/symfony/property-access/PropertyAccessor.php on line 442

Call Stack:
0.0003 980096 1. {main}() /sites/property-access/test.php:0
0.0150 3787888 2. Symfony\Component\Serializer\Serializer->serialize($data = class stdClass { public $bankAccount.iban = 'NL16TEST0436169118'; public $bankSummary = '' }, $format = 'json', $context = ???) /sites/property-access/test.php:47
0.0150 3788264 3. Symfony\Component\Serializer\Serializer->normalize($data = class stdClass { public $bankAccount.iban = 'NL16TEST0436169118'; public $bankSummary = '' }, $format = 'json', $context = []) /sites/property-access/vendor/symfony/serializer/Serializer.php:129
0.0150 3789232 4. Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->normalize($object = class stdClass { public $bankAccount.iban = 'NL16TEST0436169118'; public $bankSummary = '' }, $format = 'json', $context = []) /sites/property-access/vendor/symfony/serializer/Serializer.php:150
0.0150 3790360 5. Symfony\Component\Serializer\Normalizer\ObjectNormalizer->getAttributeValue($object = class stdClass { public $bankAccount.iban = 'NL16TEST0436169118'; public $bankSummary = '' }, $attribute = 'bankAccount.iban', $format = 'json', $context = ['_read_attributes' => TRUE, 'cache_key' => 'ecc5fabac235bf8e878a40312bf42ca4', 'circular_reference_limit_counters' => ['00000000000000160000000000000000' => 1]]) /sites/property-access/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php:194
0.0150 3790360 6. Symfony\Component\PropertyAccess\PropertyAccessor->getValue($objectOrArray = class stdClass { public $bankAccount.iban = 'NL16TEST0436169118'; public $bankSummary = '' }, $propertyPath = 'bankAccount.iban') /sites/property-access/vendor/symfony/serializer/Normalizer/ObjectNormalizer.php:134
0.0153 3821504 7. Symfony\Component\PropertyAccess\PropertyAccessor->readPropertiesUntil($zval = [0 => class stdClass { public $bankAccount.iban = 'NL16TEST0436169118'; public $bankSummary = '' }], $propertyPath = class Symfony\Component\PropertyAccess\PropertyPath { private array $elements = [0 => 'bankAccount', 1 => 'iban']; private int $length = 2; private array $isIndex = [0 => FALSE, 1 => FALSE]; private array $isNullSafe = [0 => FALSE, 1 => FALSE]; private string $pathAsString = 'bankAccount.iban' }, $lastIndex = 2, $ignoreInvalidIndices = TRUE) /sites/property-access/vendor/symfony/property-access/PropertyAccessor.php:107
0.0153 3821720 8. Symfony\Component\PropertyAccess\PropertyAccessor->readProperty($zval = [0 => class stdClass { public $bankAccount.iban = 'NL16TEST0436169118'; public $bankSummary = '' }], $property = 'bankAccount', $ignoreInvalidProperty = FALSE, $isNullSafe = FALSE) /sites/property-access/vendor/symfony/property-access/PropertyAccessor.php:309

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      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