- var_dump: documentation ( source)
<?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('---');
}