What are the potential pitfalls of using constants in PHP for storing sensitive data?

Storing sensitive data in constants in PHP can be risky because constants are easily accessible and cannot be changed during runtime. This means that if an attacker gains access to your codebase, they can easily retrieve sensitive information like API keys or passwords. To mitigate this risk, it is recommended to store sensitive data in environment variables or a secure configuration file outside of the web root.

// Instead of storing sensitive data in constants
define('API_KEY', '1234567890');

// Store sensitive data in environment variables
$api_key = getenv('API_KEY');