<?php
declare(strict_types=1);
final class CreateStatementRequest
{
private ?DateTimeImmutable $startDate, $endDate;
public function __construct(
DateTimeImmutable $startDate = null,
DateTimeImmutable $endDate = null
) {
$this->startDate = $startDate;
$this->endDate = $endDate; // error: Property CreateStatementRequest::$endDate (DateTimeImmutable) does not accept DateTimeImmutable|null.
}
public function hasFilterStartDate(): bool
{
return $this->startDate !== null;
}
public function getFilterStartDate(): DateTimeImmutable
{
if ($this->startDate === null) {
throw new RuntimeException('The start date filter is not defined.');
}
return $this->startDate;
}
public function hasFilterEndDate(): bool
{
return $this->endDate !== null;
}
public function getFilterEndDate(): DateTimeImmutable
{
if ($this->endDate === null) { // error: Strict comparison using === between DateTimeImmutable and null will always evaluate to false.
throw new RuntimeException('The end date filter is not defined.');
}
return $this->endDate;
}
}
$ref = new \ReflectionClass(CreateStatementRequest::class);
foreach ($ref->getProperties() as $refProperty) {
var_dump($refProperty->getName());
$refType = $refProperty->getType();
var_dump($refType->getName());
var_dump($refType->allowsNull());
var_dump('---');
}
Deprecated: CreateStatementRequest::__construct(): Implicitly marking parameter $startDate as nullable is deprecated, the explicit nullable type must be used instead in /in/hITTk on line 8
Deprecated: CreateStatementRequest::__construct(): Implicitly marking parameter $endDate as nullable is deprecated, the explicit nullable type must be used instead in /in/hITTk on line 8
string(9) "startDate"
string(17) "DateTimeImmutable"
bool(true)
string(3) "---"
string(7) "endDate"
string(17) "DateTimeImmutable"
bool(true)
string(3) "---"