K
K
ksiment2020-04-12 04:52:11
PHP
ksiment, 2020-04-12 04:52:11

After switching to php 7.1, the error A non-numeric value encountered?

Hello! After switching to PHP 7.1 in the admin panel, an error A non-numeric value encountered in type-reviews.php on line 218 appeared when creating a post with the "review" function. It doesn’t interfere much, but a post with a review is not created either (the panel does not appear)

// Prepare rating marks to save
if ( !function_exists( 'marksToSave' ) ) {
  function marksToSave($marks) {
    $maxLevel = max(5, (int) get_custom_option('reviews_max_level'));
    if ($maxLevel == 100) return $marks;
    $m = explode(',', $marks);
    $kol = count($m);
    for ($i=0; $i < $kol; $i++) {
      $m[$i] = round($m[$i] * 100 / $maxLevel, 1);
    }
    return implode(',', $m);
  }
}


// Prepare rating marks to display
if ( !function_exists( 'marksToDisplay' ) ) {
  function marksToDisplay($marks) {
    $maxLevel = max(5, (int) get_custom_option('reviews_max_level'));
    if ($maxLevel == 100) return $marks;
    $m = explode(',', $marks);
    $kol = count($m);
    for ($i=0; $i < $kol; $i++) {
      $m[$i] = round($m[$i] / (int) 100 * $maxLevel, 1); //218 строка
    }
    return implode(',', $m);
  }
}
?>


Please help, I don't understand what is the problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Belyaev, 2020-04-12
@ksiment

Try like this

//$m[$i] = round($m[$i] / (int) 100 * $maxLevel, 1);
$m[$i] = (((int) $m[$i]) /(100 * ((int) $maxLevel)));
$m[$i] = round($m[$i], 1);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question