I read about how to determine the encoding of a file in PHP, and in some blog or somewhere, it was suggested to do this:
if (function_exists('mb_detect_encoding')) {
function is_utf8($str) {
}
} else {
function is_utf8($str) {
}
}
It seems very dirty to me and can be replaced with this:
function is_utf8($str) {
if (...) {
} else {
}
}
However, I also see that it also has some advantages. Depending on how complex the operator ifis and how often the function is called, this can be much more efficient. My question is this: at what point could you consider dividing a function into two, as in the first example? Are there any other pros / cons that I missed?
Change . Please do not dwell on the example here, the question of this practice as a whole.
nickf