<?php
class SerialDateTime extends DateTime implements JsonSerializable{
public function jsonSerialize(){
return ['timestamp' => $this->getTimestamp()];
}
public function __toString(){
return $this->getTimestamp();
}
// TODO: Is this the best way, or is there a better way?
public static function createFromFormat($f, $t, $tz=NULL){
$dateTime = call_user_func(
array('SerialDateTime', 'parent::createFromFormat'),
$f, $t, $tz
);
$ret = new self();
return $ret->setTimestamp($dateTime->getTimestamp());
}
}
echo strnatcasecmp(new SerialDateTime, new SerialDateTime('January 1, 2013'));
Deprecated: Return type of SerialDateTime::createFromFormat($f, $t, $tz = null) should either be compatible with DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/rIL9e on line 14
Deprecated: Return type of SerialDateTime::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/rIL9e on line 5
1
Output for 8.0.0 - 8.0.30
1
Output for 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Method SerialDateTime::__toString() must return a string value in /in/rIL9e:24
Stack trace:
#0 /in/rIL9e(24): strnatcasecmp(Object(SerialDateTime), Object(SerialDateTime))
#1 {main}
thrown in /in/rIL9e on line 24
Process exited with code 255.