Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PropertyAccess] SimpleXMLElement object property value cannot be set dynamically #53398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
renatogcarvalho opened this issue Jan 4, 2024 · 3 comments

Comments

@renatogcarvalho
Copy link

Symfony version(s) affected

v5.4+

Description

The PropertyAccess component on version v5.4+ no longer can set a value to a SimpleXMLElement class property dynamically.

I noticed there were some changes made on #37622 and #44419, however this issue is still happening for the SimpleXMLElement class at least.

How to reproduce

Code snippet:

<?php

require_once 'vendor/autoload.php';

use Symfony\Component\PropertyAccess\PropertyAccess;

$xml = new \SimpleXMLElement(<<<XML
<root>
    <message></message>
</root>
XML
);

$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
    ->getPropertyAccessor();

dump($xml);

$propertyAccessor->setValue($xml, 'message', 123);

dump($xml);

Result on v4.4.44:

➜  sf-4-4 git:(main) ✗ php test.php
SimpleXMLElement {#2
  +"message": SimpleXMLElement {#16}
}
SimpleXMLElement {#2
  +"message": "123"
}

Result on v5.4.26:

➜  sf-5-4 git:(main) ✗ php test.php 
SimpleXMLElement {#2
  +"message": SimpleXMLElement {#20}
}
PHP Fatal error:  Uncaught Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException: Could not determine access type for property "message" in class "SimpleXMLElement". in /sf-5-4/vendor/symfony/property-access/PropertyAccessor.php:604
Stack trace:
#0 /sf-5-4/vendor/symfony/property-access/PropertyAccessor.php(175): Symfony\Component\PropertyAccess\PropertyAccessor->writeProperty(Array, 'message', 123)
#1 /sf-5-4/test.php(20): Symfony\Component\PropertyAccess\PropertyAccessor->setValue(Object(SimpleXMLElement), 'message', 123)
#2 {main}
  thrown in /sf-5-4/vendor/symfony/property-access/PropertyAccessor.php on line 604

Possible Solution

No response

Additional Context

In our use case we use the component to parse XML API responses, and sometimes need to make adjustments to certain node elements.

For the time being we can obviously adjust the code to set the property values directly (i.e. $xml->property = 'value'), however would be great if this can be fixed as it simplifies our implementation.

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants