I have a class method that deals with dates:
public function setAvailability(DateTime $start, DateTime $end){
}
Since item availability can have lower limit, upper limit, both or none, I'd like to make setAvailability() accept NULL values as well. However, the NULL
constant violates the type hinting:
$foo->setAvailability(NULL, $end);
triggers:
Catchable fatal error: Argument 1 passed to Foo::setAvailability() must be an instance of DateTime, null given
And, as far as I know, I cannot have a DateTime instance with no value. (Can I?)
For a reason I cannot grasp, this seems to work:
public function setAvailability(DateTime $start=NULL, DateTime $end=NULL){
}
...
$foo->setAvailability(NULL, $end);
But it looks like a hack that works by pure chance.
How would you deal with unset dates in PHP classes?