From: [EMAIL PROTECTED] Operating system: Solaris i think PHP version: 4.1.2 PHP Bug Type: *General Issues Bug description: array issue in object
i have created a class called filter. i have two variables in the class which are arrays. i have an method named approve which sets the values of both arrays. however the arrays both get set to the same value. here is the relevant portion of the filter class code. class Filter{ var $filter_name = "Basic Filter"; var $allowed_number = 0; var $filter_word_file; // file name string var $violations; // array of strings of violating keywords var $keywords; // array of strings of keywords in content // Basic filter constructor. // Returns : nothing // Parameters : $file_name File containing restricted words. function Filter($file_name){ $this->filter_word_file=$file_name; } // Compares passed content to restricted file. Approved if unwanted content falls // in range specified by $violation_count. // Returns : true if approved // false if not approved // Parameters : $content the content to test function approve($content){ $word_arr = file($this->filter_word_file); $content_arr = split(" ",$content); $violation_count = 0; $violation_arr; $keyword_arr; $run_once = true; for($i=0;$i<count($word_arr);$i++){ for($j=0;$j<count($content_arr);$j++){ if(ereg(trim($word_arr[$i]),$content_arr[$j])){ $violation_arr[$violation_count] = $content_arr[$j]; $violation_count++; }else{ if((strlen($content_arr[$j])>4)&& ($run_once == true)){ $keyword_arr[] = $content_arr[$j]; } } } $run_once = false; } //***** THIS IS THE CODE THAT IS BUGGY!!!! ****** $this->$violations = $violation_arr; $this->$keywords = $keyword_arr; //***** NOW HERE BOTH $keywords and $violations ARE SET TO THE VALUE OF $keyword_arr ***** if($violation_count>$allowed_number){ return false; } return true; } // Sets the number of allowed violations. // Return : nothing // Parameters : $number Amount of violations to allow. function setAllowedViolationNumber($number){ $this->$allowed_number = $number; } // Returns an array of content violations. // Return : array of strings // Parameters : none function getViolatingContent(){ return $this->$violations; } // Returns an array of keywords for content. // Return : array of strings // Parameters : none function getKeywords(){ echo count($keywords); return $this->$keywords; } } Anyway I can always re-produce this bug and I think there is something seriously wrong here. -- Edit bug report at http://bugs.php.net/?id=16947&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=16947&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=16947&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=16947&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=16947&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=16947&r=support Expected behavior: http://bugs.php.net/fix.php?id=16947&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=16947&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=16947&r=submittedtwice