From 0aa5e8c428c54e25e588eb8373f109fddbb19814 Mon Sep 17 00:00:00 2001 From: huanglonghui <1592328848@qq.com> Date: Tue, 9 Jul 2024 22:07:26 +0800 Subject: [PATCH] fix: Fixed the compatibility issue of DOMDocument::createCDATASection function --- src/SplArray.php | 2 +- test/ArrayTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/SplArray.php b/src/SplArray.php index 1001fbc..0c160a9 100644 --- a/src/SplArray.php +++ b/src/SplArray.php @@ -253,7 +253,7 @@ public function toXML($CD_DATA = false, $rootName = 'xml', $subArrayItemKey = 'i public function addCData($cdata_text) { $dom = dom_import_simplexml($this); - $cdata = $dom->ownerDocument->createCDATASection($cdata_text); + $cdata = $dom->ownerDocument->createCDATASection((string)$cdata_text); $dom->appendChild($cdata); } }; diff --git a/test/ArrayTest.php b/test/ArrayTest.php index dc2c8fa..d55b394 100644 --- a/test/ArrayTest.php +++ b/test/ArrayTest.php @@ -419,6 +419,31 @@ public function testToXML(SplArray $splArrayObj) { ); } + /** + * 转化成xml + */ + public function testToXML2() + { + $data = [ + 'fruit' => [ + 'apple' => 2, + 'orange' => 1, + 'grape' => 4, + 'foo' => null, + ], + 'color' => [ + 'red' => 12, + 'blue' => 8, + 'green' => 6 + ] + ]; + $splArrayObj = new SplArray($data); + $this->assertEquals( + "\n", + $splArrayObj->toXML(true) + ); + } + public function testMulti() { $splArray = new SplArray(