ID: 16947 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: *General Issues Operating System: Solaris i think PHP Version: 4.1.2 New Comment:
i am trying to set the object variables $violations and $keywords to be $violation_arr and $keyword_arr respectively. the assignment itself works however it assigns the last value in this case $keyword_arr to both. if i invert the order of the assignments doing the $violation assignment last then both are set to that value. i do not believe the problem has anything to do with my use of this-> because again a value is being assigned but it is assigning to more than one variable. of additonal note it does not set any of the other variables $filter_name, $allowed_number and $filter_word_file. Previous Comments: ------------------------------------------------------------------------ [2002-05-01 14:04:12] [EMAIL PROTECTED] So what are you trying to do in those lines? $this->$violations expands to $this->array(.....). You want to make assign several properties all at once? Or is: $this->violations=$arr_violations; the code you're looking for? And if so, does that fix the bug? ------------------------------------------------------------------------ [2002-05-01 12:22:44] [EMAIL PROTECTED] 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 this bug report at http://bugs.php.net/?id=16947&edit=1