If you really what to optimize, don't use an array and a foreach loop. That will be more readable but a little less easy to add an other option.

```php
if (isset($context['xml_version'])) {
    $document->xmlVersion = $context['xml_version'];
}
```