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
https://forums.phpfreaks.com/topic/140447-solved-function-will-not-return-value/
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?

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 )

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.