title: Convert type hinted php8 objects to json using json_encode
body: <p>I have the following code.</p>
  <pre><code>class SomeObject implements JsonSerializable {
      public string $placeholder;
      public string $id;
      public string $model;
      public string $value;
      public bool $disabled;
      public bool $required;
  
      public function jsonSerialize()
      {
          return get_object_vars($this);
      }
  }
  
  class MainObject implements JsonSerializable
  {
      public string $mainName;
      public SomeObject $someObject;
  
      public function __construct() {
          $this-&gt;mainName = (new ReflectionClass(MainObject::class))-&gt;getShortName();
          $this-&gt;someObject = new SomeObject();
      }
  
      public function jsonSerialize()
      {
          return get_object_vars($this);
      }
  }
  
  $main = new MainObject;
  $jsonData = json_encode($main, JSON_PRETTY_PRINT);
  
  &gt;&gt;&gt; Result:
  {
      &quot;mainName&quot;: &quot;MainObject&quot;,
      &quot;someObject&quot;: []
  }
  </code></pre>
  <p>I would like the MainObject to look like this</p>
  <pre><code>{
      &quot;mainName&quot;: &quot;MainObject&quot;,
      &quot;someObject&quot;: {
          &quot;placeholder&quot;: &quot;&quot;,
          &quot;id&quot;: &quot;&quot;,
          &quot;model&quot;: &quot;&quot;,
          &quot;value&quot;: &quot;&quot;,
          &quot;disabled&quot;: &quot;&quot;,
          &quot;required&quot;: &quot;&quot;
      }
  }
  </code></pre>
  <p>however it seems that json_encode() method will only encode if objects have values assigned to them. if I make $someObject an associative array it works as expected.</p>
  <p>How can I do this? Thanks in advance.</p>