php - Define two functions, or branch within one? -


I was reading about the encoding of a file in PHP, and on some blogs or somewhere, this suggestion To do this:

  if (function_exists ('mb_detect_encoding')) {function is_utf8 ($ str) {// do mub * libraries using stuff}} and {function I_utf8 ($ str) {// do stuff manually}} I think this is very messy, and can be changed with:  
  function Is_utf8 ($ str) {if (...) {// MB stuff here} else {// manual stuff here}}   

However, I can also see that there are some benefits too. It depends on how much the complexity is, and how often the function is called if It can be more efficient, my question is: At what point would you divide a function in two ways in two ways, such as in the first instance?

Edit : Please do not hang on the example here, the question is normally about this exercise.

My stomach reaction is to go with the same declaration of the is_utf8 function. The PHP engine is very good in optimization and function_exists () should be negligible in the overhead of many calls.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -