What are some potential pitfalls of using the extract() function in PHP?

Using the extract() function in PHP can lead to potential variable name conflicts and security vulnerabilities if not used carefully. To avoid these pitfalls, it is recommended to explicitly define the variables you want to extract from an array to prevent unexpected variable overwrites or injections.

$data = [
    'name' => 'John',
    'age' => 30,
    'email' => 'john@example.com'
];

// Explicitly define the variables to extract
extract($data, EXTR_SKIP);
echo $name; // Output: John
echo $age; // Output: 30
echo $email; // Output: john@example.com