What are the potential pitfalls of using relative paths in PHP scripts, and what is the recommended alternative?

Using relative paths in PHP scripts can lead to issues when the script is executed from different directories, as the relative path will be calculated based on the current working directory. To avoid this problem, it is recommended to use absolute paths instead, which provide a fixed reference to the file or directory regardless of the current working directory.

// Using absolute path to include a file
include_once(__DIR__ . '/path/to/file.php');