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

Bug #3315 frequency() generates notices
Submitted: 2005-01-27 18:41 UTC
From: cmoehrke at netviser dot de Assigned: jmcastagnetto
Status: Closed Package: Math_Stats
PHP Version: 5.0.3 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2005-01-27 18:41 UTC] cmoehrke at netviser dot de
Description: ------------ Using frequency() results in an number of notices. Reproduce code: --------------- require_once('Math/Stats.php'); $dat = array (1,3,4,2,2,1,3,3,1,3); $stat=new Math_Stats(); $erg=$stat->setData($dat); if (true==PEAR::isError($erg)) { die ($erg->getMessage()); } $erg=$stat->frequency(); if (true==PEAR::isError($erg)) { die ($erg->getMessage()); } var_dump($erg); Expected result: ---------------- array(4) { [1]=> int(3) [2]=> int(2) [3]=> int(4) [4]=> int(1) } Actual result: -------------- Notice: Undefined index: 1 in /usr/local/php/pear/Math/Stats.php on line 1216 Notice: Undefined index: 2 in /usr/local/php/pear/Math/Stats.php on line 1216 Notice: Undefined index: 3 in /usr/local/php/pear/Math/Stats.php on line 1216 Notice: Undefined index: 4 in /usr/local/php/pear/Math/Stats.php on line 1216 array(4) { [1]=> int(3) [2]=> int(2) [3]=> int(4) [4]=> int(1) }

Comments

 [2005-01-27 18:48 UTC] cmoehrke at netviser dot de
Here's a little fix for it. Line 1216 is actually: $freq["$val"]++; to fix this bug it could be changed to: isset($freq["$val"])? $freq["$val"]++:$freq["$val"]=1;
 [2005-02-02 20:27 UTC] jmcastagnetto
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. Sorry could not apply your fix earlier. I was on my way to Lima, Peru, and just today I got some reliable internet connection. I ended up using code that is a tad more verbose, but that shows the intent easily (future-proofing the maintenance of the code :-). Thanks for your contribution. Cheers. -- Jesus M. Castagnetto