gish Posted January 12, 2009 Share Posted January 12, 2009 hi, chronister helped with some of the code in the sorting_class early today. Now I am trying to do the same thing with oop. The code below is what i already. But I can't get any values to return and i get no errors. Is anyone able to help. class question_collation { private $posted_variable; private $Yes = 0; private $No = 0; private $Unsure = 0; private $Missed = 0; private $k; public function sorting_class ($posted_variable){ //posted variable is setup so as to sort if it is a yes no or unsure foreach($posted_variable as $k) { switch($_POST[$k]) { case '': $this->Missed++; break; case 1: $this->Yes++; break; case 2: $this->No++; break; case 3: $this->Unsure++; break; } } } public function missed_return(){ return $this->$Missed; } public function yes_return(){ return $this->$Yes; } public function no_return(){ return $this->$No; } public function unsure_return(){ return $this->$Unsure; } } $posted_variable = array('business','performance','budget','structure','goals','customer','document','aims','swot','systems','work','delegate'); $question_collation_object = new question_collation; $question_collation_object ->sorting_class ($posted_variable); echo $question_collation_object ->missed_return . '<br/>This is the missed'; echo $question_collation_object ->yes_return . '<br/>This is the yes'; echo $question_collation_object ->no_return . '<br/>This is the no '; echo $question_collation_object ->unsure_return . '<br/>This is the unsure'; ?> Quote Link to comment Share on other sites More sharing options...
corbin Posted January 12, 2009 Share Posted January 12, 2009 $question_collation_object ->missed_return should be $question_collation_object ->missed_return() As should all of the other ones. Quote Link to comment Share on other sites More sharing options...
gish Posted January 12, 2009 Author Share Posted January 12, 2009 Thanks for that it now i am getting some errors, which is great =) Fatal error: Cannot access empty property in /online.php on line 109 109 is this one, return $this->$Missed; when I posted it on the other page, I did not select two values so it should have the value of 2. does any one have any idea? Quote Link to comment Share on other sites More sharing options...
gish Posted January 12, 2009 Author Share Posted January 12, 2009 I know what the problem is, but i don't know how to fix it. Inside the function I did the following line. echo print_r($posted_variable,1); Which I should not do in oop but for testing purposes =). The output is the following, It gets the array but does not pass on the array values. Any ideas Array ( [0] => business [1] => performance [2] => budget [3] => structure [4] => goals [5] => customer [6] => document [7] => aims [8] => swot [9] => systems [10] => work [11] => delegate ) Quote Link to comment Share on other sites More sharing options...
gish Posted January 12, 2009 Author Share Posted January 12, 2009 hi there is nothing wrong with the code except public function missed_return(){ return $this->$Missed; } public function yes_return(){ return $this->$Yes; } public function no_return(){ return $this->$No; } public function unsure_return(){ return $this->$Unsure; } the variables need to be return $this->Unsure; and so on Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.