After using PHP for close to two years, and being delighted with it, I have realised that I need to move forward and learn OOP.
I wrote a class to double a number inputted from a form, which looks like this:
<?php
class testclass {
public function double($demo) {
return $demo * 2;
}
}
?>
I then decided to try to be clever and insert a method to validate the data, prior to doubling the number. The idea was to have the new validation method call the 'double' method if all validates ok. I know I could call the method from the same script that the form is on, but I want to call it from within the class. I tried this but it didn't work:
<?php
class testclass {
public function validate($demo) {
if($demo!=''){
$this->double($demo);
}else {
return 'Please enter number';
}
}
public function double($demo) {
return $demo * 2;
}
}
?>
So, can someone tell me why it doesn't work and how to make it work? The validation part works ok, but it's not calling the 'double' function.