最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - PHP 7.1 | Warning: A non-numeric value encountered in

programmeradmin0浏览0评论

Warning: A non-numeric value encountered in line 107.

<div class="like">
    <?php 
        $nonce = wp_create_nonce("my_user_vote_nonce");
        $likeLink = admin_url('admin-ajax.php?action=my_user_vote&custom=like&post_id='.$post->ID.'&nonce='.$nonce);            
    ?>
    <a class="like" data-image="<?php bloginfo('template_url');?>/images/loading.gif" data-field="like" data-nonce="<?php echo $nonce ?>" data-post_id="<?php echo $post->ID ?>" href="<?php echo $link ?>" title="Like"><span><?php echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.'); ?></span></a>
</div>

line 107

<a class="like" data-image="<?php bloginfo('template_url');?>/images/loading.gif" data-field="like" data-nonce="<?php echo $nonce ?>" data-post_id="<?php echo $post->ID ?>" href="<?php echo $link ?>" title="Like"><span><?php echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.'); ?></span></a>

Warning: A non-numeric value encountered in line 107.

<div class="like">
    <?php 
        $nonce = wp_create_nonce("my_user_vote_nonce");
        $likeLink = admin_url('admin-ajax.php?action=my_user_vote&custom=like&post_id='.$post->ID.'&nonce='.$nonce);            
    ?>
    <a class="like" data-image="<?php bloginfo('template_url');?>/images/loading.gif" data-field="like" data-nonce="<?php echo $nonce ?>" data-post_id="<?php echo $post->ID ?>" href="<?php echo $link ?>" title="Like"><span><?php echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.'); ?></span></a>
</div>

line 107

<a class="like" data-image="<?php bloginfo('template_url');?>/images/loading.gif" data-field="like" data-nonce="<?php echo $nonce ?>" data-post_id="<?php echo $post->ID ?>" href="<?php echo $link ?>" title="Like"><span><?php echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.'); ?></span></a>
Share Improve this question edited Mar 13, 2020 at 12:12 Ersin asked Mar 13, 2020 at 11:45 ErsinErsin 31 silver badge3 bronze badges 2
  • You have a lot of stuff on that line, can you split it into multiple lines so that we can figure out which part is the problem? I have a suspicion where it is. Otherwise, are you asking where the warning is, what the warning means, or are you asking how to fix it? – Tom J Nowell Commented Mar 13, 2020 at 12:06
  • Thank you Tom for your help, i want to fix it. Why it is happening with PHP 7.1. – Ersin Commented Mar 13, 2020 at 12:13
Add a comment  | 

1 Answer 1

Reset to default 1

I suspect the problem is this:

echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.')

Here, we take the post meta named like and multiply it by 1, but what if that post meta doesn't contain a number? What if it contains something else?

For example, if we did 2 x 4, we would expect PHP to give us 8, which is correct, but what if we tell PHP to multiple 2 x "hello"? or

发布评论

评论列表(0)

  1. 暂无评论