#6049: Set::extract using XPath extracts data inconsistently with classic
extract
when numeric keys do not start at zero
----------------------------+-----------------------------------------------
Reporter: datac0re | Type: Bug
Status: new | Priority: High
Milestone: 1.2.x.x | Component: Core Libs
Version: 1.2 Final | Severity: Normal
Keywords: set extract | Php_version: PHP 5
Cake_version: 1.2.0.7962 |
----------------------------+-----------------------------------------------
We've been trying to move away from the classic extract and towards the
XPath format and today noticed an inconsistency with the two formats when
extracting from an array with numeric keys that don't start at zero.
Consider the following array:
{{{
Dump of variable "$data":
Array
(
[Inbound Voice] => Array
(
[0] => 1.9333
[1] => 5.4000
[2] => 5.0000
[3] => 3.5667
[4] => 1.6167
[5] => 7.4000
[6] => 11.7333
[7] => 86.9833
[8] => 2099.4000
[9] => 5322.9500
[10] => 5537.9333
[11] => 5485.1167
[12] => 4152.2000
[13] => 4657.9667
[14] => 4936.2000
[15] => 4697.4333
[16] => 3653.8500
[17] => 321.6833
[18] => 84.2667
[19] => 85.4500
[20] => 55.5833
[21] => 19.1667
[22] => 21.5000
[23] => 2.1667
)
[Outbound Voice] => Array
(
[7] => 247.1833
[8] => 2906.6000
[9] => 7099.8500
[10] => 8706.7667
[11] => 8134.2500
[12] => 5790.0000
[13] => 7792.5833
[14] => 7632.3667
[15] => 7709.5167
[16] => 6521.5333
[17] => 719.1500
[18] => 93.4333
[19] => 32.9667
[20] => 26.6167
[21] => 0.5667
)
)
}}}
Using the 'Inbound Voice' first, we did the following comparison and got
what we expected (the same results with classic and XPath):
{{{
pr(Set::extract($data, 'Inbound Voice.{n}'));
pr(Set::extract('/Inbound Voice', $data));
Array
(
[0] => 1.9333
[1] => 5.4000
[2] => 5.0000
[3] => 3.5667
[4] => 1.6167
[5] => 7.4000
[6] => 11.7333
[7] => 86.9833
[8] => 2099.4000
[9] => 5322.9500
[10] => 5537.9333
[11] => 5485.1167
[12] => 4152.2000
[13] => 4657.9667
[14] => 4936.2000
[15] => 4697.4333
[16] => 3653.8500
[17] => 321.6833
[18] => 84.2667
[19] => 85.4500
[20] => 55.5833
[21] => 19.1667
[22] => 21.5000
[23] => 2.1667
)
Array
(
[0] => 1.9333
[1] => 5.4000
[2] => 5.0000
[3] => 3.5667
[4] => 1.6167
[5] => 7.4000
[6] => 11.7333
[7] => 86.9833
[8] => 2099.4000
[9] => 5322.9500
[10] => 5537.9333
[11] => 5485.1167
[12] => 4152.2000
[13] => 4657.9667
[14] => 4936.2000
[15] => 4697.4333
[16] => 3653.8500
[17] => 321.6833
[18] => 84.2667
[19] => 85.4500
[20] => 55.5833
[21] => 19.1667
[22] => 21.5000
[23] => 2.1667
)
}}}
Then we did the same test with the 'Outbound Voice', which if you'll
notice, starts its indexing at 7 instead of zero and got inconsistent
results:
{{{
pr(Set::extract($data, 'Outbound Voice.{n}'));
pr(Set::extract('/Outbound Voice', $data));
Array
(
[0] => 247.1833
[1] => 2906.6000
[2] => 7099.8500
[3] => 8706.7667
[4] => 8134.2500
[5] => 5790.0000
[6] => 7792.5833
[7] => 7632.3667
[8] => 7709.5167
[9] => 6521.5333
[10] => 719.1500
[11] => 93.4333
[12] => 32.9667
[13] => 26.6167
[14] => 0.5667
)
Array
(
[0] => Array
(
[Outbound Voice] => Array
(
[7] => 247.1833
[8] => 2906.6000
[9] => 7099.8500
[10] => 8706.7667
[11] => 8134.2500
[12] => 5790.0000
[13] => 7792.5833
[14] => 7632.3667
[15] => 7709.5167
[16] => 6521.5333
[17] => 719.1500
[18] => 93.4333
[19] => 32.9667
[20] => 26.6167
[21] => 0.5667
)
)
)
}}}
The classic extract worked as expected whereas the XPath version seemed to
get confused and returned the result incorrectly. I believe this is a bug
in the XPath implementation.
--
Ticket URL: <https://trac.cakephp.org/ticket/6049>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---