1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
<?php
class Foo
{
public string $time_string {
get {
return $this->date->format('H:i:s');
}
}
public function __construct(
private DateTime $date = new DateTime('1979-01-01 00:00:00') {
set (string|DateTime $value) {
if (is_string($value)) {
$this->date = new DateTime($value);
} else {
$this->date = $value;
}
}
}
)
{
}
function setNewDate( string|DateTime $date )
{
$this->date = $date;
}
}
$date = new DateTime('1980-01-01 00:00:00' );
$foo = new Foo();
$foo->setNewDate( '1970-01-01 12:34:56' );
echo $foo->time_string;
echo '';
?>
|