What are the potential security risks of displaying user passwords or sensitive information in PHP code and how can they be mitigated?

Displaying user passwords or sensitive information in PHP code can pose a significant security risk as it exposes this information to anyone who has access to the codebase. To mitigate this risk, it is recommended to store sensitive information in environment variables and access them securely within the code.

// Store sensitive information in environment variables
$database_host = getenv('DB_HOST');
$database_username = getenv('DB_USERNAME');
$database_password = getenv('DB_PASSWORD');
$database_name = getenv('DB_NAME');

// Connect to the database using the environment variables
$conn = new mysqli($database_host, $database_username, $database_password, $database_name);