- var_dump: documentation ( source)
<?php
class MyRequest
{
public function __construct()
{
$reflectedProperties = (new \ReflectionClass($this))->getProperties();
foreach ($reflectedProperties as $property) {
!$property->isInitialized($this) &&
$property->getType()->allowsNull() ? $property->setValue($this, null) : null;
}
}
}
class PostRequest extends MyRequest
{
public ?string $title;
public string $name;
}
$postRequest = new PostRequest();
$postRequest->name = 'foo';
// works fine - I have access here!
foreach($postRequest as $property) {
var_dump($property);
}