Error_log: PHP Warning: A non-numeric value encountered

Dušan

After updating to PHP 7.3 I get the following error

PHP Warning: A non-numeric value encountered in /functions.php on line 3702

Line 3702:

$total += $rating['rating_score'];

Function code:

function airkit_get_rating( $post_id ) {

if ( is_numeric($post_id) ) {
    $rating_items = get_post_meta($post_id, 'ts_post_rating', TRUE);
    if ( isset($rating_items) && is_array($rating_items) && !empty($rating_items) ) {
        $total = '';
        foreach($rating_items as $rating) {
            $total += $rating['rating_score'];
        }
        if ( $total > 0 ) {
            $round = intval($total) / count($rating_items);
            $result = round($round, 1);

            if ( is_int($round) ) {
                if ( $round == 10 ) return $result;
                else return $result . '.0';
            } else {
                return $result;
            }
        } else {
            return;
        }
    }
} else {
    return;
}}

I have no experience in PHP. Can anyone help me to correct this error?

Barmar

Change

$total = '';

to

$total = 0;

You're trying to add a number to a string, but the string doesn't look like a number. The empty string is converted to the number 0, so you get the correct total, but it also produces a warning.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

PHP Warning: A non-numeric value encountered in

Warning - A non-numeric value encountered after upgrade to php 7.1

PHP Warning: A non-numeric value encountered need fix

How do I fix my "PHP Warning: A non-numeric value encountered" error?

Getting Error Warning: A non-numeric value encountered in

Warning: A non-numeric value encountered problem

Warning: A non-numeric value encountered

A non-numeric value encountered error in php 7.1

A non well formed numeric value encountered - Error in PHP

Warning: A non-numeric value encountered to upgrade my open cart php version

PHP 7.4.21 - A non-numeric value encountered

A non-numeric value encountered in PHP 7.3.8

A non well formed numeric value encountered in php

Q: A non-numeric value encountered (PHP)

symfony 1.4 - Warning: A non-numeric value encountered

API error - A non-numeric value encountered

PHP error: A non-numeric value encountered in file.php on line 180 in file_exists function

How to solve a non well formed numeric value encountered in PHP?

PHP 7.1 'A non-numeric value encountered' with Twig 1.35

How to debug "A non-numeric value encountered" in PHP?

A non-numeric value encountered PHP MYSQL opencart

php Laravel- A non well formed numeric value encountered (on string)

phpgraphlib A non-numeric value encountered for php version 7.1

a non well formed numeric value encountered codeigniter php 7.*

Warning: A non-numeric value encountered in <b>C:\xampp\htdocs\bab2\index.php</b> on line <b>126</b>

Laravel A non-numeric value encountered on functions

Notice: A non well formed numeric value encountered

A non-numeric value encountered with Laravel

A non well formed numeric value encountered in laravel