I constantly run into this and there has to be a better way to do it. So I have an Order Class and an Order_db class. in the order class there is a property $orderDate that is a DateTime object.
The problem is that sometimes the $orderDate is null. So it seems I have to options:
When I do a select query I test to see if there was date before calling my setter. When I do an Insert query I check that $orderDate isn't null before trying to perform a ->format (as that would throw an error)
I test in the setter if anything was passed before creating a new DateTime object but I'm still stuck with testing if it exists before using it with ->format.
It's not that big of a deal but I deal with a lot of date fields and it gets pretty repetitive. Is there a better way to handle this? In my ideal world if I passed nothing to DateTime when creating a instance it would be null, and if I called ->format on a null DateTime it would return nothing instead of throwing an error.