PHP operates on a stream of text. It doesn't care what the text is. It is either just outputting the input or (when inside a <?php
section) running PHP. It doesn't know about HTML.
Validity (in this context) only matters in the context of the generated HTML. The HTML will be valid if the PHP outputs valid content, and that will depend on what require_once 'somefile.php';
outputs.