Are there any best practices for defining and using constants in PHP to prevent errors?

When defining and using constants in PHP, it is important to follow best practices to prevent errors. One common mistake is defining constants with inconsistent naming conventions or without proper validation. To prevent errors, constants should be defined using uppercase letters with underscores separating words, and their values should be immutable throughout the code.

define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', 'password');
define('DB_NAME', 'database');

// Example of using constants
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);