What are some common pitfalls to avoid when optimizing PHP code for performance, especially premature optimization?

One common pitfall to avoid when optimizing PHP code for performance is premature optimization, which involves making optimizations before identifying where the actual bottlenecks are. It's important to first profile the code to pinpoint areas that need improvement before making changes. Additionally, focusing on optimizing algorithms and data structures can often yield better results than micro-optimizations.

// Premature optimization example
// Avoid optimizing code before identifying bottlenecks

// Premature optimization
$start = microtime(true);

for ($i = 0; $i < 1000; $i++) {
    // Some code that may not be a bottleneck
}

$end = microtime(true);
$executionTime = $end - $start;

echo "Execution time: " . $executionTime . " seconds";