I'm practising coding in an object oriented way; experimenting with taking some frequently used scripts for form handling and turning them into functions. Here is my code.
class FormHandler{
// Secure simple inputs
public function secure($var){
$var = stripslashes($var);
$var = strip_tags($var);
$var = htmlentities($var);
return $var;
}
public function getAll(){
foreach($_POST as $key => $value){
${$key} = secure($_POST[$key]);
}
$didGetAll =TRUE;
}
public function echoResults(){
if($didGetAll === TRUE){
echo "Form Contents<br>";
foreach($_POST as $key => $value){
echo $key." => ".${$key}."<br>";
}
}else{
echo 'do getAll() fuction first'."<br>";
}
}
}
When I run the functions like so:
include './formhandling.php';
$form = new FormHandler;
$form -> getAll();
$form -> echoResults();
it returns the 'do getAll() fuction first' message even though the $didGetAll var should = true.
I assume this is because the variable values aren't being passed between functions?
I've tried to test this by making $didGetAll global, and by doing return $didGetAll. But it still returns the same result.
Could someone suggest what I'm doing wrong?