What are the common pitfalls when implementing Caesar encryption and decryption in PHP?

One common pitfall when implementing Caesar encryption and decryption in PHP is not handling the wrap-around of the alphabet correctly. When shifting characters, it's important to ensure that if the shift goes beyond 'z', it wraps back to 'a'. This can be achieved by using the modulus operator with the alphabet length.

function caesarEncrypt($text, $shift) {
    $result = "";
    $text = strtoupper($text);
    $shift = $shift % 26;

    for ($i = 0; $i < strlen($text); $i++) {
        if ($text[$i] >= 'A' && $text[$i] <= 'Z') {
            $result .= chr(((ord($text[$i]) - 65 + $shift) % 26) + 65);
        } else {
            $result .= $text[$i];
        }
    }

    return $result;
}