title: Get type of typed property in PHP 7.4
body: <p>I have a <code>DTO</code> with typed PHP variables:</p>
  
  <pre><code>class CreateMembershipInputDto extends BaseDto
  {
      public bool $is_gift;
      public int $year;
      public string $name;
      public \DateTime $shipping_date;
      public ContactInputDto $buyer;
      public ?ContactInputDto $receiver;
  }
  </code></pre>
  
  <p>I am trying to make some kind of automapper, which fills the properties, but I need to check the type of the variable but that seems to be impossible.</p>
  
  <pre><code>class BaseDto
  {
      public function __construct($json)
      {
          $jsonArray = json_decode($json, true);
          foreach($jsonArray as $key=&gt;$value){
              $type = gettype($this-&gt;$key);
              if($type instanceof BaseDto)
                  $this-&gt;$key = new $type($value);
              else
                  $this-&gt;$key = $value;
          }
      }
  }
  </code></pre>
  
  <p><strong>ContactInputDto:</strong></p>
  
  <pre><code>class ContactInputDto extends BaseDto
  {
      public string $firstname;
      public string $lastname;
      public string $street_housenumber;
      public string $postal_code;
      public string $place;
      public string $country;
      public string $email;
      public string $phone;
  }
  </code></pre>
  
  <p>Is it somehow possible to make that line <code>"gettype($this-&gt;$key)"</code> work, without php throwing the following error:</p>
  
  <blockquote>
    <p>Typed property App\Dto\CreateMembershipInputDto::$is_gift must not be accessed before initialization</p>
  </blockquote>