How can absolute paths be used effectively in PHP scripts to ensure consistent functionality across different directories?

When working with PHP scripts that need to access files or resources across different directories, using absolute paths can ensure consistent functionality. Absolute paths specify the full path to a file or directory on the server, regardless of the current working directory. This prevents issues with relative paths breaking if the script is executed from different locations.

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