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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!