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

From: Date: Thu, 23 Apr 2020 18:37:59 +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-17511@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: andrew dot bent at insuremytrip dot com 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 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? Previous Comments: ------------------------------------------------------------------------ [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 (#17511) next »