What potential security risks should be considered when outputting source code on a webpage using PHP?

One potential security risk when outputting source code on a webpage using PHP is the possibility of exposing sensitive information such as API keys, database credentials, or other confidential data. To mitigate this risk, it's important to sanitize the source code before displaying it to the user. This can be done by removing any sensitive information or by using PHP functions like htmlentities() to escape special characters.

<?php
// Sanitize the source code before outputting
$sourceCode = file_get_contents('example.php');
$sourceCode = htmlentities($sourceCode);
echo "<pre>$sourceCode</pre>";
?>