Doc #79485 [Com]: Minor version update changed how json_encode serialzies SimpleXMLElement

From: Date: Thu, 30 Apr 2020 21:53:29 +0000
Subject: Doc #79485 [Com]: Minor version update changed how json_encode serialzies SimpleXMLElement
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17548@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79485&edit=1 ID: 79485 Comment by: ttijhof at wikimedia dot org Reported by: p dot szymkowski at lottestyle dot de Summary: Minor version update changed how json_encode serialzies SimpleXMLElement Status: Closed Type: Documentation Problem Package: JSON related Operating System: Linux PHP Version: 7.3.17 Block user comment: N Private report: N New Comment: This changed has caused observable changes in user-land code in a bug release, which seems like something that should not happen. An isolated test case exists at https://3v4l.org/HtN9R. This is not debugging output, these are run-time return values. And it doesn't even rely on reflection or something hacky like that. This kind of breaking API change is something that should be reserved for major releases. PHP 8.0 territory, not PHP 7.3.17. Previous Comments: ------------------------------------------------------------------------ [2020-04-23 18:37:59] andrew dot bent at insuremytrip dot com This fix has broken a lot of our code that relies on the serialization operating the way that it previously did. Anyone who is serializing simplexml now probably has broken code. > Anyhow, I wonder why you would expect json_encode() to strip the attribute of the element? Because it's behaved like this for nearly a decade and there are now many implementations depend on it being "broken". Can you reconsider re-opening this bug please? ------------------------------------------------------------------------ [2020-04-17 12:21:47] p dot szymkowski at lottestyle dot de I see. I'm closing this bug report, I should not serialize SimpleXMLElements in first place ------------------------------------------------------------------------ [2020-04-17 12:08:32] cmb@php.net That change is not specific to json_encode, but rather caused by the more general fix for bug #61597. We usually do not document bug fixes. Anyhow, I wonder why you would expect json_encode() to strip the attribute of the element? ------------------------------------------------------------------------ [2020-04-17 11:55:15] p dot szymkowski at lottestyle dot de Description: ------------ Minor update 7.3.16 -> 7.3.17 changed json_encode() behaviour and it's not documented or mentioned in change log Test script: --------------- <?php $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <Response> <Element someAttribute="foo">Bar</Element> </Response> XML; echo json_encode(simplexml_load_string($xml), true); Expected result: ---------------- {"Element":"Bar"} Actual result: -------------- {"Element":{"@attributes":{"someAttribute":"foo"},"0":"Bar"}} ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79485&edit=1

« previous php.doc.bugs (#17548) next »