Skip to content

SimpleXMLElement Should Accept String #8236

@oleibman

Description

@oleibman

Bug report

We are having problems adding a string with an ampersand as a text element to a SimpleXMLElement node using addChild. Researching, I found https://stackoverflow.com/questions/2970575/php-simplexmlelement-set-text and applied its solution. It absolutely solves our problem. However, Phpstan complains "SimpleXMLElement does not accept string."

Code snippet that reproduces the problem

https://phpstan.org/r/79d3daf7-1686-4da3-abcd-b1329578af0c

Expected output

Phpstan should report no errors.

I believe Phpstan should not be reporting an error for assigning a string to element [0] of a simpleXMLElement. FWIW, https://onlinephp.io/c/d98a5 demonstrates that the code works correctly in all relevant Php versions.

Did PHPStan help you today? Did it make you happy in any way?

Yes, it helps. Thank you for producing and continuing to support it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions