Connect with us

Humor

UTF-16 Encoding

[ad_1]

Let’s say you were browsing through some code, and saw a function signature like this:

function changeUTF16( $string )

What do you think that function does? Given the name, I suspect it converts a UTF-16 string into some other encoding, or perhaps it changes some other encoding to UTF-16. Either way, the name is fairly unclear, and probably could be better.

P-O sent this in, and let’s take a look at what the function actually does.










function changeUTF16( $string ){
    return mb_convert_encoding( $string, "ISO-8859-1", "UTF-8" )."n" ;
}

Thank the gods for that NOTE there, which awkwardly describes what the function actually does- it converts a UTF-8 string to an ISO-8859-1 string. ISO-8859 is, notably, not UTF-16, and in fact, isn’t 16 bits at all– it’s just a different 8-bit encoding from UTF-8.

Clearly, none of this ever mattered, because the program worked, but equally clearly the person behind this method had no clue what character encodings actually meant.

P-O did find that converting this function to a no-op had no impact on the application.

[ad_2]

Remy Porter

Source link