I'm getting my feet wet in OOP and have a question about __construct()
content:
Suppose I want to make a PlayResult
class, which will take protected ID
,Date
, and Winner
properties. That would seem like logical things to put in the __construct()
method, but the ID
is the unique auto-incremented ID generated by MySQL when the play result is added to the table for the first time.
Now the ID is very important to my code, because that's how I keep track of individual records when they're being edited. However, obviously when a user uses an HTML form to submit a new play result there is no ID value because the result has not yet entered the database.
So, should the ID go in the constructor or not? Or should I construct with date and winner only, then set the ID if I have one?
Thanks :-)