1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. To combat forum spam, new accounts will need to make at least one (valid) post.
    Otherwise, we will periodically purge all users without posts or that haven't confirmed their account.

Fatal error: Cannot redeclare utf8_substr()

Discussion in 'Installation / Upgrade Questions' started by Amelia Pereira, Dec 23, 2008.

Thread Status:
Not open for further replies.
  1. Amelia Pereira

    Amelia Pereira New Member

    Hello, I installed easycalendar on 2 sites in the same domain. The 2 calendars share the same DB, and at the beginnning they worked fine.

    Suddenly, on one site appeared the error :
    Fatal error: Cannot redeclare utf8_substr() (previously declared in /home/estcsite/public_html/dmh/modules/calendar/functions/calendar.php:191) in /home/estcsite/public_html/dmh/libraries/phputf8/mbstring/core.php on line 90

    and the joomla site does not show. I have to disable the easycalendar module. But on the other site it works fine.

    site with problem: www.es-tc.net/dmh

    site with no problem: www.es-tc.net/dmhestc

    What happened??:confused:
     
  2. Brian

    Brian EPC Developer Staff Member

    Does the calendar/demo.php file work correctly on the problem domain?

    Has anything changed on the server recently (PHP version, etc)?

    Are the paths correct for each installation of the calendar in the calendar directory?
     
  3. Amelia Pereira

    Amelia Pereira New Member

    Hello
    yes, the demo file worked... php did not change, and if it had, it would affect both calendars sib┬źnce they are in the same place, just in diferent folders...

    as for the paths... I think they are OK. How can I check them?
     
  4. Brian

    Brian EPC Developer Staff Member

    Check the Paths Errors link in my signature below. :)
     
  5. Amelia Pereira

    Amelia Pereira New Member

    Well Brian
    I just erased the path form the config file and entered setup... the paths were updates but the error remains.
    :sad:

    I also compared the config file with the one on the working site, and everythingseems to be the same... except for the paths...
     
  6. Brian

    Brian EPC Developer Staff Member

    The error is not actually the calendar, but something in your core.php file (full path in your first post).

    The calendar uses a function called utf8_substr and apparently the core.php file does also. However, the calendar checks to make sure this variable hasn't been used before trying to declare it. It appears that core.php does not and it is trying to re-declare this function (which PHP doesn't allow).

    Can you edit the core.php file?
     
  7. Amelia Pereira

    Amelia Pereira New Member

    of course Brian, here it is:
    <?php
    /**
    * @version $Id: core.php 10381 2008-06-01 03:35:53Z pasamio $
    * @package utf8
    * @subpackage strings
    */
    /**
    * Define UTF8_CORE as required
    */
    if ( !defined('UTF8_CORE') ) {
    define('UTF8_CORE',TRUE);
    }
    //--------------------------------------------------------------------
    /**
    * Assumes mbstring internal encoding is set to UTF-8
    * Wrapper around mb_strpos
    * Find position of first occurrence of a string
    * @param string haystack
    * @param string needle (you should validate this with utf8_is_valid)
    * @param integer offset in characters (from left)
    * @return mixed integer position or FALSE on failure
    * @package utf8
    * @subpackage strings
    */
    function utf8_strpos($str, $search, $offset = FALSE){
    if(strlen($str) && strlen($search)) {
    if ( $offset === FALSE ) {
    return mb_strpos($str, $search);
    } else {
    return mb_strpos($str, $search, $offset);
    }
    } else return FALSE;
    }
    //--------------------------------------------------------------------
    /**
    * Assumes mbstring internal encoding is set to UTF-8
    * Wrapper around mb_strrpos
    * Find position of last occurrence of a char in a string
    * @param string haystack
    * @param string needle (you should validate this with utf8_is_valid)
    * @param integer (optional) offset (from left)
    * @return mixed integer position or FALSE on failure
    * @package utf8
    * @subpackage strings
    */
    function utf8_strrpos($str, $search, $offset = FALSE){
    if ( $offset === FALSE ) {
    # Emulate behaviour of strrpos rather than raising warning
    if ( empty($str) ) {
    return FALSE;
    }
    return mb_strrpos($str, $search);
    } else {
    if ( !is_int($offset) ) {
    trigger_error('utf8_strrpos expects parameter 3 to be long',E_USER_WARNING);
    return FALSE;
    }
    $str = mb_substr($str, $offset);
    if ( FALSE !== ( $pos = mb_strrpos($str, $search) ) ) {
    return $pos + $offset;
    }
    return FALSE;
    }
    }
    //--------------------------------------------------------------------
    /**
    * Assumes mbstring internal encoding is set to UTF-8
    * Wrapper around mb_substr
    * Return part of a string given character offset (and optionally length)
    * @param string
    * @param integer number of UTF-8 characters offset (from left)
    * @param integer (optional) length in UTF-8 characters from offset
    * @return mixed string or FALSE if failure
    * @package utf8
    * @subpackage strings
    */
    function utf8_substr($str, $offset, $length = FALSE){
    if ( $length === FALSE ) {
    return mb_substr($str, $offset);
    } else {
    return mb_substr($str, $offset, $length);
    }
    }
     
  8. Amelia Pereira

    Amelia Pereira New Member

    could it be some other joomla module that messed with that core.php file, and easyphpcalendar stopped working because of that?
    because the only thing I was doing was to install some moduleson my site...
     
  9. Amelia Pereira

    Amelia Pereira New Member

    Well, now I decided to uninstall and install the joomla module again, and when I access the module I get this message
    JFolder::files: Path is not a folder /home/estcsite/public_html/dmh/calendar/templates

    I thought it was supposed to install calendar inside the modules folder...:confused: right?

    I really don't understand why it is not working on this site, and it works on the other one. how strange...
     
  10. Brian

    Brian EPC Developer Staff Member

    The calendar is working. Something in core.php added a function with the same name as the calendar and is trying to re-declare it and causing PHP to show an error.

    That function in core.php would need to be renamed and it could be caused by a module. (I don't know anything about Joomla so I can't be sure.)
     
  11. Amelia Pereira

    Amelia Pereira New Member

    well, I accessed the core.php file and changed the function name from utf8_substr to utf8_subs... and the page now works... the question is: what consequences has this change??? I'll have to wait and see. Thanks Brian.
     
  12. ve9gra

    ve9gra Support Team

    More than likely that it was a setting that you changed in your Joomla setup to enable UTF-8. Or you installed a module that uses that function. Like Brian said, it is not related to the calendar as it properly does a check (whereas the Joomla function doesn't).

    Changing the Joomla function's name without digging into what the function does might break Joomla things. To properly do a name change, you would have to do a search and replace on all the Joomla code to a new name.... and that would of course bring you out of line with the official Joomla package, so you wouldn't be able to use the patches. Any time that you'd install a new version (if not using a patch), that modification would need to be redone.

    Your best course of action is to figure out what triggered the usage of that function, and change that setting back.
     
  13. ve9gra

    ve9gra Support Team

    Brian, can you check the code in utf8_substr() in the calendar code and see if this code is similar?

    PHP:
    function utf8_substr($str$offset$length FALSE){
        if ( 
    $length === FALSE ) {
            return 
    mb_substr($str$offset);
        } else {
            return 
    mb_substr($str$offset$length);
        }
    }
     
  14. Brian

    Brian EPC Developer Staff Member

    They are not remotely similar...
     
  15. ve9gra

    ve9gra Support Team

    That's what I was expecting... which means that if the Joomla function is renamed, and producing a specific output, when Joomla will finally use that function and receive something unexpected, you might get into problems.

    The Joomla forums would be better equipped to let you know either what feature to disable, or how to fix this issue.
     
Thread Status:
Not open for further replies.

Share This Page