What are the potential pitfalls of using undefined constants in PHP scripts, and how can they be avoided?

Using undefined constants in PHP scripts can lead to errors or unexpected behavior in your code. To avoid this, always define constants before using them in your script. You can define constants using the `define()` function or by using the `const` keyword.

// Define a constant before using it
define('MY_CONSTANT', 'Hello World');

// Using the constant
echo MY_CONSTANT;