Jump to content

[SOLVED] function will not return value


gish

Recommended Posts

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';
?>


Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 )

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.