How can the copy-paste-principle impact the accuracy of PHP scripts, and what alternative approaches can be taken to avoid errors?

The copy-paste-principle can impact the accuracy of PHP scripts by introducing errors when code is duplicated and modified inconsistently. To avoid this, developers should strive to refactor duplicated code into reusable functions or classes, reducing the likelihood of errors and making maintenance easier.

// Example of refactoring duplicated code into a reusable function

function calculateArea($length, $width) {
    return $length * $width;
}

$rectangle1Area = calculateArea(5, 10);
$rectangle2Area = calculateArea(3, 7);