Answer the question
In order to leave comments, you need to log in
Conflict of identical functions. How to fix?
Guys help. There is a declension function
<?php defined('JPATH_BASE') or die;
$comments = JPATH_SITE . '/components/com_jcomments/jcomments.php';
if (file_exists($comments)) {
require_once($comments);
$options = array();
$options['object_id'] = $id;
$options['object_group'] = 'com_content';
$options['published'] = 1;
$count = JCommentsModel::getCommentsCount($options);
/* Cклонение числительных */
$form1 = JText::_('INVIP_PREVIEW_COMMENT');
$form2 = JText::_('INVIP_PREVIEW_COMMENTS');
$form3 = JText::_('INVIP_PREVIEW_COMMENTSS');
$form4 = JText::_('INVIP_PREVIEW_NONE_COMMENTS');
function format_by_count($count, $form1, $form2, $form3){
$count = abs($count) % 100;
$lcount = $count % 10;
if ($count >= 11 && $count <= 19) return($form3);
if ($lcount >= 2 && $lcount <= 4) return($form2);
if ($lcount == 1) return($form1);
return $form3;
}
$counts = $count ? ($count . ' ' . format_by_count($count, $form1, $form2, $form3)) : $form4;
}
?>
<li class="attr comments">
<meta itemprop="commentsUserCount" content="<?php echo $count; ?> UserComments" />
<?php echo $counts; ?>
</li>
Answer the question
In order to leave comments, you need to log in
0) "an error is obtained" - a bad description of the problem. At a minimum, you need to write the text of the error and the line.
1) I can assume in telepath mode that the file you provided is called in a loop for each article.
Accordingly, you get the 2nd definition of the format_by_count function.
In general, it is better never to define a function in a conditional block, but to define it somewhere higher.
The problem can be solved locally
if (!function_exists("format_by_count")) {
function format_by_count($count, $form1, $form2, $form3){
$count = abs($count) % 100;
$lcount = $count % 10;
if ($count >= 11 && $count <= 19) return($form3);
if ($lcount >= 2 && $lcount <= 4) return($form2);
if ($lcount == 1) return($form1);
return $form3;
}
}
but it's still shitty code. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question