2

I moved a website from server (PHP 5.6.38) to localhost (PHP 7.2.10). And I receive this error in the page title (in the chrome tab):

0 - Using $this when not in object content

While searching online I found that I have to replace all instances of JSite::getMenu() with JFactory::getApplication()->getMenu(), I did it with no luck. I changed the theme and the error dissapeared, so its probably something with the theme. I tried to edit the theme but I receive this error :

An error has occurred.

0 syntax error, unexpected '}', expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF)

Return to Control Panel

But there is no information where this error is.

I downloaded again the template files from server, replace the local ones but still get the same error, while on the live server there is no such error

EDIT

I enabled error_reporting and I get this error:

Parse error: syntax error, unexpected '}' in C:...\html\modules.php on line 64

The problem is that the file is identical with the one on the server and on the server I dont get any error...

Here is the code:

function modChrome_myCatMod($module, &$params, &$attribs)
{
    $moduleTag      = $params->get('module_tag', 'div');
    $headerTag      = htmlspecialchars($params->get('header_tag', 'h3'));
    $bootstrapSize  = (int) $params->get('bootstrap_size', 0);
    $moduleClass    = $bootstrapSize != 0 ? ' span' . $bootstrapSize : '';

    // Temporarily store header class in variable
    $headerClass    = $params->get('header_class');
    $headerClass    = ($headerClass) ? ' class="' . htmlspecialchars($headerClass) . '"' : '';

    if (!empty ($module->content)) : ?>
        <<?php echo $moduleTag; ?> class="moduletable<?php echo htmlspecialchars($params->get('moduleclass_sfx')) . $moduleClass; ?>" id="Mod<?php echo $module->id;?>">
            <?php if ((bool) $module->showtitle) : ?>
                <?php $com_content_categories = $params->get('com_content_categories'); if(!empty($com_content_categories)): 
                    $caturl = ContentHelperRoute::getCategoryRoute ( $com_content_categories[0] );
                ?>
                <<?php echo $headerTag . $headerClass . '>' ?><a href="<?php echo $caturl;?>"><?php  echo $module->title; ?></a></<?php echo $headerTag; ?>>                                                    
                <?php else : ?>             
                <<?php echo $headerTag . $headerClass . '>' . $module->title; ?></<?php echo $headerTag; ?>>                    
                <? endif;?>

            <?php endif; ?><?php echo $module->content; ?>
        </<?php echo $moduleTag; ?>>
    <?php endif; 
}     //////////////////////////////////error line
11
  • Enable Debug in Global Configuration to see where the error is coming from.
    – Sharky
    Commented Nov 27, 2018 at 15:05
  • What is the version of Joomla? does the backend work correctly with you? Commented Nov 27, 2018 at 16:37
  • ...and what is the theme that you are using? Commented Nov 27, 2018 at 19:40
  • It looks very likely you have outdated Joomla or old extensions - which aren't compatible with php 7.2x. Why did you move to localhost? I guess for updates or other development. In such cases, it is better to initially clone the site in a similar environment to start your tasks (updates etc) and then update your PHP. As for the new error - about the elseif - you need to enable debug. If you only made any changes in your template, then probably the problem is somewhere in there, and it may be easy to spot it by reading the code.
    – FFrewin
    Commented Nov 28, 2018 at 6:31
  • 1
    If you have Error Reporting in your Global Configiration set to development it should provide a stack trace
    – Lodder
    Commented Nov 28, 2018 at 8:17

1 Answer 1

1

Don't quote me on this but I have a feeling it may be due to the mixing of curly braces and alternative syntax.

I've rewritten your modChrome using curly braces:

function modChrome_myCatMod($module, &$params, &$attribs)
{
    $moduleTag      = $params->get('module_tag', 'div');
    $headerTag      = htmlspecialchars($params->get('header_tag', 'h3'));
    $bootstrapSize  = (int) $params->get('bootstrap_size', 0);
    $moduleClass    = $bootstrapSize != 0 ? ' span' . $bootstrapSize : '';

    // Temporarily store header class in variable
    $headerClass    = $params->get('header_class');
    $headerClass    = ($headerClass) ? ' class="' . htmlspecialchars($headerClass) . '"' : '';

    if (!empty ($module->content))
    {
        echo '<' . $moduleTag . ' class="moduletable' . htmlspecialchars($params->get('moduleclass_sfx')) . $moduleClass . '" id="Mod' . $module->id . '">';
            if ((bool) $module->showtitle)
            {
                $com_content_categories = $params->get('com_content_categories');

                if (!empty($com_content_categories))
                {
                    $caturl = ContentHelperRoute::getCategoryRoute($com_content_categories[0]);
                    echo '<' . $headerTag . $headerClass . '><a href="' . $caturl . '">' . $module->title . '</a></' . $headerTag . '>';
                }
                else
                {
                    echo '<' . $headerTag . $headerClass . '>' . $module->title . '</' . $headerTag . '>';
                }

                }
            echo $module->content;
        echo '</' . $moduleTag . '>';
    }
}

Hope this solves the issue.

That said, if you have not provided the entire contents of this file in your question, I'd suggest doing so as the error may actually derive from a different line.

1
  • Ah nice. Glad it worked :)
    – Lodder
    Commented Nov 28, 2018 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.