How can you prevent accidentally overwriting the $_COOKIE array in PHP?

Accidentally overwriting the $_COOKIE array in PHP can be prevented by storing the values in a separate variable before modifying the $_COOKIE array. This way, the original values can be easily restored if needed. Another approach is to use a custom naming convention for the cookie keys to avoid conflicts with existing keys in the $_COOKIE array.

// Store the values in a separate variable before modifying the $_COOKIE array
$myCookie = $_COOKIE;
// Modify the $_COOKIE array as needed
$_COOKIE['new_cookie'] = 'value';
// Restore the original values if needed
$_COOKIE = $myCookie;