So I’m playing around with OOP in PHP. I only do this part time, a few times per week so excuse me if this is a dumb question.
If for example I have a person class.
When a form is submitted I create a new instance of that person
“`$Person = new Person($_POST[‘personaName’]);
For example.
And within the Person Class I have a constructor;
“`
public function __construct($personName){
$personName = $personName;
}
However, If I want to get a person from my database. How can I do something like
“`
$PersonClass = new Person;
$Person = $PersonClass->searchById($_GET[‘ID’]);
Where this method looks up the person in my database and creates them?
Does this second class need be just that, a complete second class which constructs and returns the Person?