I am building a website, but in order to improve my coding skills, I am trying to do this using the power of OOP.
I use classes to validate form input, so I thought that I would have a “parent” validation class, and then child classes for each form to be submitted (for example, an input class, registration class, etc.), which will take care of the right values in the database etc.
The code I saw has a parent created from a child constructor. However, I did not do this, but it seems my class is working?
Can someone explain to me why we are calling the parent constructor from the child? Also, my code only works because I have “public” functions (methods) with my parent? (is this a potential problem)?
My code (shortened version for clarity) is below:
class Validation_Class
{
public function __construct()
{
}
public function is_genuine_email_address($email) {
}
}
My child class looks like ...
class Login_Class extends Validation_Class
{
public function __construct()
{
}
}
All my functions (methods) in my Validation_Class are "publicly available", and when I instantiate my child class, I can call any of the methods of the validation class with:
$className = "Login_Class";
$thisClass = new $className();
source
share