Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.21.0

Bug #17577 Array index being used as tag name rather than object name
Submitted: 2010-07-10 14:01 UTC
From: markcorbyn Assigned:
Status: Open Package: XML_Serializer (version 0.20.0)
PHP Version: 5.2.9 OS: Windows 7
Roadmaps: (Not assigned)    
Subscription  


 [2010-07-10 14:01 UTC] markcorbyn (Mark Corbyn)
Description: ------------ When serialising an array containing multiple Country objects, the first xml node inside the root is the Country tag, but all the others are invalid numerical tags e.g. <1>...</1><2>...</2> I've tracked down to a solution which currently works for me, but there may be undesired side-effects I'm unaware of. Line 1129 of Serializer.php checks for if(empty($tagName)). In the case of the first Country array value, the $tagName = 0 which eveluates to empty(), whereas the others don't evaluate to empty(), making the first one refer to the get_class($object) whereas subsequence array values just use the $tagName. Sample print_r() of the array being privided to serializer: Array ( [0] => Country Object ( [CountryCode] => AD [CountryName] => ANDORRA [RegionID] => 2 [VisaRequired] => [VisaApprovalWeeks] => [VisaCompletionDeadlineWeeks] => ) [1] => Country Object ( [CountryCode] => AE [CountryName] => UNITED ARAB EMIRATES [RegionID] => 8 [VisaRequired] => [VisaApprovalWeeks] => [VisaCompletionDeadlineWeeks] => ) [2] => Country Object ( [CountryCode] => AF [CountryName] => AFGHANISTAN [RegionID] => 8 [VisaRequired] => [VisaApprovalWeeks] => [VisaCompletionDeadlineWeeks] => ) [3] => Country Object ( [CountryCode] => AG [CountryName] => ANTIGUA AND BARBUDA [RegionID] => 3 [VisaRequired] => [VisaApprovalWeeks] => [VisaCompletionDeadlineWeeks] => ) [4] => Country Object ( [CountryCode] => AI [CountryName] => ANGUILLA [RegionID] => 3 [VisaRequired] => [VisaApprovalWeeks] => [VisaCompletionDeadlineWeeks] => ) ) Sample result: <array> <Country> <CountryCode>AD</CountryCode> <CountryName>ANDORRA</CountryName> <RegionID>2</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </Country> <1> <CountryCode>AE</CountryCode> <CountryName>UNITED ARAB EMIRATES</CountryName> <RegionID>8</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </1> <2> <CountryCode>AF</CountryCode> <CountryName>AFGHANISTAN</CountryName> <RegionID>8</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </2> <3> <CountryCode>AG</CountryCode> <CountryName>ANTIGUA AND BARBUDA</CountryName> <RegionID>3</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </3> <4> <CountryCode>AI</CountryCode> <CountryName>ANGUILLA</CountryName> <RegionID>3</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </4> </array> Solution aqpplied, change line 1129 from: if (empty($tagName)) { to if (empty($tagName) || is_numeric($tagName)) { Expected result: ---------------- <array> <Country> <CountryCode>AD</CountryCode> <CountryName>ANDORRA</CountryName> <RegionID>2</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </Country> <Country> <CountryCode>AE</CountryCode> <CountryName>UNITED ARAB EMIRATES</CountryName> <RegionID>8</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </Country> <Country> <CountryCode>AF</CountryCode> <CountryName>AFGHANISTAN</CountryName> <RegionID>8</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </Country> <Country> <CountryCode>AG</CountryCode> <CountryName>ANTIGUA AND BARBUDA</CountryName> <RegionID>3</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </Country> <Country> <CountryCode>AI</CountryCode> <CountryName>ANGUILLA</CountryName> <RegionID>3</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </Country> </array> Actual result: -------------- <array> <Country> <CountryCode>AD</CountryCode> <CountryName>ANDORRA</CountryName> <RegionID>2</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </Country> <1> <CountryCode>AE</CountryCode> <CountryName>UNITED ARAB EMIRATES</CountryName> <RegionID>8</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </1> <2> <CountryCode>AF</CountryCode> <CountryName>AFGHANISTAN</CountryName> <RegionID>8</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </2> <3> <CountryCode>AG</CountryCode> <CountryName>ANTIGUA AND BARBUDA</CountryName> <RegionID>3</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </3> <4> <CountryCode>AI</CountryCode> <CountryName>ANGUILLA</CountryName> <RegionID>3</RegionID> <VisaRequired /> <VisaApprovalWeeks /> <VisaCompletionDeadlineWeeks /> </4> </array>

Comments