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官方文档,上面解释说在使用(+ - * ...
随机推荐
- HDU-3746-Cyclic Nacklace(KMP,循环节)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- linux秘钥分发
秘钥分发 ssh-copy-id -i /root/.ssh/id_rsa.pub "-p 9000 root@192.168.1.100" 传送文件 scp -P9000 -rp ...
- python基础知识06-函数基础和函数参数
函数基础和函数参数 可迭代对象:序列类型 range . 1.函数的定义 def 函数名(参数): pass return 表达式 ,不能是赋值语句.不写默认返回None.用逗号隔开返回一个元组. 函 ...
- 昨天去面试,这5个Python面试题都被考到了,Python面试题No6
第1题:字符串的拼接–如何高效的拼接两个字符串? 字符串拼接的几种方法 加号 逗号 直接连接 格式化 join 多行字符串拼接() 加号 print('Python' + 'Plus') 逗号 pri ...
- 我的Python分析成长之路1
Python是什么? ...
- 《算法导论》— Chapter 15 动态规划
序 算法导论一书的第四部分-高级设计和分析技术从本章开始讨论,主要分析高效算法的三种重要技术:动态规划.贪心算法以及平摊分析三种. 首先,本章讨论动态规划,它是通过组合子问题的解而解决整个问题的,通常 ...
- hls简述(HTTP live Streaming)
hls官方地址:https://developer.apple.com/streaming/ IDR: Instantaneous Decoding Refresh (IDR) start code ...
- Pollard rho模板
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #in ...
- hdu4115:Eliminate the Conflict
n<=10000局剪刀石头布,对面第i局出Ai,m<=10000种对你出什么提出的要求:Xi Yi Wi 表示第Xi局和第Yi局,Wi=1:必须不同:Wi=0:必须相同,问是否存在你一局都 ...
- poj1190,DFS/已知一个等式,求另一个最小值
7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱. ...