What are the potential pitfalls of using references in PHP compared to JavaScript?

One potential pitfall of using references in PHP compared to JavaScript is that PHP references are more explicit and can lead to unintended side effects if not used carefully. To avoid these pitfalls, it's important to be mindful of when and where references are being used in PHP code and ensure they are necessary for the desired functionality.

// Potential pitfall: unintended side effects with references
$var1 = 5;
$var2 = &$var1;
$var2 = 10;

echo $var1; // Output will be 10, not 5 as expected

// Fix: avoid using references if not necessary
$var1 = 5;
$var2 = $var1;
$var2 = 10;

echo $var1; // Output will be 5 as expected