3

For a public app - do you think it's a good idea to assume the mb_string extension is enabled on all servers (or almost all, like 95%)?

Are there hosts out there that disable this extension?

Alex
  • 66,732
  • 177
  • 439
  • 641
  • 2
    It's normally available, but not always. You should document with your software which requirements it has and/or display them prior installation. Rolling your own sounds a bit like re-inventing the wheel. – hakre Sep 27 '11 at 18:13
  • @hakre: Good **answer**. Why is it up here? :-) – Herbert Sep 27 '11 at 18:18

1 Answers1

2

I think most have it enabled by default but I've known a few hosting providers that don't, and who also then refused to enable it (never did get a good reason out of them).

If you want all users to be able to install the app on their server without any changes then you'll probably want to roll your own set of functions.

However it might be a better solution to make mb_string a pre-requisite of your app (and perhaps test for it's existence in the installation script) then you'd be able to save yourself that extra work, while still providing a satisfactory user experience.

If you take Drupal as an example of a public app, they actually roll their own functions (e.g. drupal_substr() and drupal_strlen()), in which they test for the existence of the mb_string extension and make the decision on how to run the function based on that.

Clive
  • 36,918
  • 8
  • 87
  • 113
  • I can't understand why, in this day and age, mb_string isn't enabled by default in the PHP installation. **Refusing** to enable it is simply irresponsible (IMHO) on the part of the hosting provider. – Herbert Sep 27 '11 at 18:24
  • @Herbert I couldn't agree more, as far as I'm concerned `mb_string` is essential...why on earth wouldn't you want to use faster string functions?? – Clive Sep 27 '11 at 18:25
  • For checking if the extension is enabled, do you think it's better to use `defined('MB_OVERLOAD_STRING')` instead of function_exists() ? I think it would be faster to check if a constant is defined – Alex Sep 27 '11 at 18:35
  • According to the [docs page](http://php.net/manual/en/function.function-exists.php), `function_exists()` 'Checks the list of defined functions' so I'd assume they've already been loaded into memory somewhere. The list of available constants will also be in memory somewhere so I'm not sure there would be that much difference. I'm not positive though and I'd be inclined to lean towards `defined` too! – Clive Sep 27 '11 at 18:39
  • @Alex: The speed difference (if there is one) would be so miniscule that it doesn't really matter. Such micro-optimization isn't going to give you any noticeable gain. So, it's really a matter of style. (i.e. which do you prefer?!) – Herbert Sep 27 '11 at 19:02