What are the best practices for handling PHP extensions like cURL to avoid fatal errors in scripts?

When using PHP extensions like cURL, it is important to check if the extension is loaded before using its functions to avoid fatal errors in scripts. One way to handle this is by using the `extension_loaded()` function to check if the extension is available before using it in your code.

if (extension_loaded('curl')) {
    // cURL extension is available, proceed with using cURL functions
    $ch = curl_init();
    // cURL operations
    curl_close($ch);
} else {
    // cURL extension is not available, handle the situation accordingly
    echo 'cURL extension is not loaded';
}