Re: Php.XPath 3.2 released!!
Brought to you by:
bs_php,
nigelswinson
From: Nigel S. <nig...@us...> - 2002-07-22 19:53:29
|
> > I've tagged this one as "stable" because it's > > been a while since there were any bug reports, but if you spot any, > > then let us know and we'll do another release. > > the sum function no longer seems to work - seems to always return 0. > Given: > > <km>100</km> > <km>200</km> > > evaluate("sum(//km)") > should surely return 300. > > This was working in 3.0. And the prize for finding the first 3.2 bugs goes to.... Peter :o) My humblest apologies, I never use the sum() function, and there was no entry in the test harness, so I only gave it a cursory glance during the coding for 3.2. I thought sum() took a single integer argument, when in fact it is meant to take a node set. :o( This has been fixed now, and a test added to the test harness so that future releases will never suffer from this bug :o) The changes are fairly slight, just change the function to this: function _handleFunction_sum($arguments, $context) { $arguments = trim($arguments); // Trim the arguments. // Evaluate the arguments as an XPath query. $result = $this->_evaluateExpr($arguments, $context); $sum = 0; // Create a variable to save the sum. // The sum function expects a node set as an argument. if (is_array($result)) { // Run through all results. $size = sizeOf($result); for ($i=0; $i<$size; $i++) { $value = $this->_handleFunction_number($result[$i], $context); $sum += doubleval($value); // Add it to the sum. } } return $sum; // Return the sum. } Let me know if this doesn't fix the problem properly... Nigel |