I'm updating some PHP 5 code to PHP 7+ standards.
We have a AcmeDate class that extends DateTime and using setTime() is generating deprecated notices.
public function setTime($hours, $minutes, $seconds = 0, $microseconds = 0) {
parent::setTime ( $hours, $minutes, $seconds, $microseconds );
}
E_DEPRECATED Return type of AcmeDate::setTime($hours, $minutes, $seconds = 0, $microseconds = 0) should either be compatible with DateTime::setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0): DateTime, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
I understand that DateTime::setTime() has a DateTime type because the core code is:
#[TentativeType]
public function setTime(
#[LanguageLevelTypeAware(['8.0' => 'int'], default: '')] $hour,
#[LanguageLevelTypeAware(['8.0' => 'int'], default: '')] $minute,
#[LanguageLevelTypeAware(['8.0' => 'int'], default: '')] $second = 0,
#[PhpStormStubsElementAvailable(from: '7.1')] #[LanguageLevelTypeAware(['8.0' => 'int'], default: '')] $microsecond = 0
): DateTime {}
But AFAIK the setTime() function doesn't actually return anything.
Adding : DateTime to AcmeDate::setTime() yields a Fatal Error:
public function setTime($hours, $minutes, $seconds = 0, $microseconds = 0):DateTime {
parent::setTime ( $hours, $minutes, $seconds, $microseconds );
}
Fatal error: Uncaught TypeError: AcmeDate::setTime(): Return value must be of type DateTime, none returned in /home/Acme/AcmeDate.php:116
Using null as a return type also throws an error saying it can't be standalone:
Fatal error: Null can not be used as a standalone type in ...
Using never throws a different error about implicit returns which I don't understand:
AcmeDate::setTime(): never-returning function must not implicitly return in...
I'm at a loss at this point. I'm sure it's something simple.