What are common pitfalls when working with references in PHP4, and how can they affect the values of variables?

Common pitfalls when working with references in PHP4 include accidentally modifying the original variable when working with references, leading to unexpected behavior and bugs in the code. To avoid this, it is important to be mindful of when references are being used and ensure that changes made to the reference variable do not unintentionally affect the original variable.

// Incorrect usage of references in PHP4
$originalVariable = 10;
$referenceVariable = &$originalVariable;
$referenceVariable = 20;

echo $originalVariable; // Output will be 20, as $originalVariable was modified through $referenceVariable

// Correct usage of references in PHP4
$originalVariable = 10;
$referenceVariable = $originalVariable;
$referenceVariable = 20;

echo $originalVariable; // Output will be 10, as $originalVariable remains unchanged