You mean here or in general? If we allow traversable then the only solution that I could think of is

```php

   foreach ($value as $k => $v) {
      $result[$k] = $v instanceof self ? $v->toArray() : $v;
   }