PHP出现Warning: A non-numeric value encountered问题的原因及解决方法
本文介绍php出现Warning: A non-numeric value encountered问题,用实例分析出现这种错误的原因,并提供避免及解决问题的方法。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on'); $a = '123a';
$b = 'b456'; echo $a+$b;
?>
以上代码执行后会提示 Warning: A non-numeric value encountered
查看PHP7.1官方文档,对这种错误的解释
New E_WARNING and E_NOTICE errors have been introduced when invalid strings are coerced using operators expecting numbers (+ - * / ** % << >> | & ^) or their assignment equivalents. An E_NOTICE is emitted when the string begins with a numeric value but contains trailing non-numeric characters, and an E_WARNING is emitted when the string does not contain a numeric value.
在使用(+ - * / ** % << >> | & ^) 运算时,例如a+b,如果a是开始一个数字值,但包含非数字字符(123a),b不是数字值开始时(b456),就会有A non-numeric value encountered警告。
解决方法
对于这种问题,首先应该在代码逻辑查看,为何会出现混合数值,检查哪里出错导致出现混合数值。
对于(+ - * / ** % << >> | & ^) 的运算,我们也可以加入转换类型方法,把错误的数值转换。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on'); $a = '123a';
$b = 'b456'; echo intval($a)+intval($b);
?>
加入intval方法进行强制转为数值型后,可以解决警告提示问题。
PHP出现Warning: A non-numeric value encountered问题的原因及解决方法的更多相关文章
- php 出现Warning: A non-numeric value encountered问题的原因及解决方法
在使用(+ - * / ** % << >> | & ^) 运算时,例如a+b,如果a是开始一个数字值,但包含非数字字符(123a),b不是数字值开始时(b456),就 ...
- 一些常见warning的原因和解决方法
在入职三周后,终于赶齐了接手项目落下两个月的项目,有了一些自己的空闲时间对项目进行整理.主要整理包括类目的整合,从原来一个系统文件夹下几百个文件整改为以MVC设计思想为原则的分文件夹整理类目,井然有序 ...
- Android开发中遇到的问题(四)——Android中WARNING: Application does not specify an API level requirement!的解决方法
今天在手机上调试运行Andorid项目时,发现Console打印出"WARNING: Application does not specify an API level requiremen ...
- 关于warning: Clock skew detected. Your build may be incomplete. 的解决方法
今天发现电脑的系统时间不对,因此将时钟进行了改动,回头编译Linux kernel的时候,提演示样例如以下的warning: warning: Clock skew detected. Your ...
- 关于warning: Clock skew detected. Your build may be incomplete. 的解决方法【转】
本文转载自:http://blog.csdn.net/jeesenzhang/article/details/40300127 今天发现电脑的系统时间不正确,因此将时钟进行了修改,回头编译Linux ...
- javascript中出现identifier starts immediately after numeric literal错误原因以及解决方法
javascript遇到参数是字符型和数字型组合的参数就会出现这种错误,例如alert(1);可以正確輸出alert(str);就會報錯alert("str");可以正確輸出.
- move_base Warning: Invalid argument "/map" passed to canTransform argument target_frame的解决方法
把global_costmap_params.yaml和local_costmap_params.yaml文件里的头几行去掉“/”,然后重新编译就可以了. 效果如下:
- “Error: Encountered an improper argument”的解决方法
之前遇到过的问题,后来解决后再次遇到又忘记了, 这是keil 的bug 路径只要都是字母就可以了
- warning: a non-numeric value encountered in line *的解决方法
今天ytkah在调试项目的时候出现了一个警告warning: a non-numeric value encountered in line 694,查看php官方文档,上面解释说在使用(+ - * ...
随机推荐
- C语言int *a 和int* a的写法
- Supreme Number
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
- nginx 集群
Nginx是什么? Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器.一直纳闷这个X是怎么来 ...
- viva correction statements
* List of amendments| No. | Location | Amendments ...
- CentOS 6.5 x64 安装jdk8
1.去官网下载Linux版本的jdk8,我下载的是下面这个 2.下载xftp和xshell来操纵服务器,可以搜索一下下载安装即可,安装完成后,打开xshell,新建链接为你的云服务器的IP地址和密码, ...
- 【HDU 5934】Bomb(强连通缩点)
Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...
- POJ 3659 Cell phone Network (树的最小点覆盖, 树形DP)
题意: 给定一棵树,每个点可以覆盖自己和相邻的点, 求最少要多少个点覆盖图 #include <cstdio> #include <cstring> #include < ...
- DOS使用笔记
DOS下cd命令: cd .. 上一级目录: g: 指定当期目录到G盘,而cd g:是没有效果的: 如图: 在安装Windows服务的过程中,如果installutil为64位版本,那么编译生成项目的 ...
- Pychorm提示Unresolved reference 导入模块报错
最近使用Pychorm编写Python时,每次要引入自定义模块,就会报错,提示“Unresolved reference” Unresolved reference 'LoginClass' more ...
- URAL 2040 Palindromes and Super Abilities 2
Palindromes and Super Abilities 2Time Limit: 500MS Memory Limit: 102400KB 64bit IO Format: %I64d &am ...