I am used codegniter 1.7.1 older version for my real estate stie and it is working fine in local host xamp server.

But when i uploaded in to server, the site not working , showing error as "Fatal error: Cannot redeclare class Locale in /application/libraries/Locale.php on line 12"

pls help me how to solve this ..

thanks in advance..

Dani AI

Generated

A short diagnosis and safe fixes for "Cannot redeclare class Locale"

The error generally means your app declared a class named the same as a built-in one. PHP's intl extension exposes a built-in Locale API, so a custom Locale class on a server that has intl enabled will produce that fatal collision — it can succeed locally if intl is not enabled on your XAMPP box but fail on the host. See PHP's Locale class and the intl extension for details. PHP Locale class intl extension.

Recommended, low-risk fix (what worked for )

  • Rename the library and its class to something unique (prefix or suffix like App_locale, Locale_lib, etc.), make the file and class names match CodeIgniter's rules, and use __construct() instead of old-style constructors to stay compatible with newer PHP versions. Example pattern:
class App_locale {
    public function __construct()
    {
        // initialization
    }
}

Follow CodeIgniter library naming rules when you save and load the file. CI libraries guide and PHP constructor guidance. PHP constructors

Quick checks and cautions

  • Verify intl is present with php -m | grep intl or a phpinfo() page. phpinfo()
  • Grep the project for duplicate declarations: grep -R "class Locale" -n .
  • Removing/uninstalling php-intl (as suggested) will stop the collision but is a server-level change that can break other code; prefer renaming or namespacing first.

Recommended Answers

All 9 Replies

You are trying to redeclare the locale class in a file of yours.

It is working fine in localhost, the problem exisiting in only server.

Please post the code where you are declaring your languages.

I think its here, in local_helper.php

        function __($text, $domain = 'default') {

        $CI =& get_instance();

        $CI->load->library('Locale1');

        return $CI->locale1->tr($text, $domain);

        }



        function _e($text, $domain = 'default') {

        echo __($text, $domain);

    }

And here is Locale.php

        class Locale1 {
        //initializing
        var $_data;
        var $locale;
        var $_l10n;
        var $table;
        var $codes;
        var $default;

        function Locale() {
            $this->table = ('languages');
            $this->obj =& get_instance();
            $this->codes = $this->get_codes();
            $this->default = $this->get_default();

            if (!$this->obj->session->userdata('lang')) {
                $this->obj->session->set_userdata('lang', $this->default);
            }

            log_message('debug', 'Locale Class Initialized');

        }
        .
        .
        .
        .

        etc

I have fixed the problem now, thanks.

You loaded the locale class, did you eliminate that and it worked ?

I have renamed locale.php and its class name etc.

Ok, good work on debuging your mistakes! :)

remove Internationalization extension if not needed and restart apapche it will work !

sudo apt-get remove php5-intl --purge
sudo service apache2 restart

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.