Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Usage of setlocale in Fuel::init
  • After analyzing the fuel source code I noticed "setlocale" is used in Fuel::init - this may be an easy way of setting a locale, but it relies heavily on the platform used (and thus can fail or not work at all) and can lead to some other pitfalls and unexpected results (many of them are listed in the comments on the setlocale-php-manual-page). Shouldn't there be a way to use fuel without setlocale? Ideally of course a way to use locale settings which work everywhere, or at least a way to disable the setlocale call. I will probably just edit the fuel core to change it, but that seems an unideal approach long-term. Btw, I am rather new to frameworks, and fuel is the most impressive one I have found. Looking forward to any further developments :-)
  • What is exactly the issue you have with it?
  • If I remember correctly php 5.3 complains if you don't have a locale set...
  • Afaik that is only so for timezone, not for locale. I'm interested in the 'pitfalls' and 'unexpected behaviour'. I've read PHP's documentation on it, but apart from an issue when using thread based webservers like Apache or IIS under Windows, I don't see an issue. And with the aforementioned platforms, you'll have an issue anyway. Either the locale is set the same for all scripts running on that platform (no issue), or you'll have an issue in all your scripts.
  • @iquito: Not a horrible idea. Send over a pull request :) Start here: https://github.com/fuel/core/blob/develop/classes/fuel.php#L172 Check if static::$locale is false...if it is, don't set it. Then you can set Fuel::$locale to false in the app bootstrap, and Boom..no locale set. You send the pull request and I will accept it.
  • Yes PHP only complaints about the time zone - calling setlocale is not required.
    Harro Verton wrote on Monday 25th of July 2011:
    I'm interested in the 'pitfalls' and 'unexpected behaviour'. I've read PHP's documentation on it, but apart from an issue when using thread based webservers like Apache or IIS under Windows, I don't see an issue.

    Issues with thread based webservers and relying on a function which works differently depending on the environment already seems like a bad idea to me - sure, if somebody wants to use a locale and they know their environment and what they are doing, that's fine, but how many people just try to use fuel out-of-the-box? An additional warning on the effects of setting a locale might save some people a lot of time & effort to find out why something is not working. The php-manual does have some additional problems I certainly would have not expected: Settings locales which do not exists: http://www.php.net/manual/en/function.setlocale.php#86078
    Casting of floating points variables to strings: http://www.php.net/manual/en/function.setlocale.php#85877 If you only use an english locale you might not notice these differences, but for other countries a locale change can influence your application in ways you will not connect with something like setlocale. Also, if a different server is used for testing and for production, setlocale can mess things up because of the possibly different systems and therefore different behavior of setlocale. Thx FrenkyNet for your change - I will try to contribute myself in the future, but I haven't worked with git yet, so I may need to familiarize myself with it first. Additionally I just would change the default $locale-definition to "false" in the Fuel-class (so if you remove the locale definition from configuration, no locale is used instead of then defaulting to "en_US") and maybe add an explanation to the config file with a hint of the possible problems of a locale - meaning it depends on environment and that the setlocale-php-manual page should probably be read before using it. That may spare you from some forum questions in the future, when fuel gets more widely used ;-)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion