In what scenarios is it beneficial to omit the closing PHP tag at the end of PHP scripts, according to PHP documentation and best practices?

Omitting the closing PHP tag at the end of PHP scripts is beneficial in scenarios where the file contains only PHP code, without any HTML or whitespace after the PHP closing tag. This practice helps prevent unintended whitespace or characters from being sent to the output, which can cause issues such as "headers already sent" errors in PHP.

<?php
// PHP code here

// No closing PHP tag needed