php 出现Warning: A non-numeric value encountered问题的原因及解决方法
来源:互联网 发布:电力施工预算软件 编辑:程序博客网 时间:2024/05/29 14:42
本文介绍php出现Warning: A non-numeric value encountered问题,用实例分析出现这种错误的原因,并提供避免及解决问题的方法。
<?phperror_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警告。
解决方法
对于这种问题,首先应该在代码逻辑查看,为何会出现混合数值,检查哪里出错导致出现混合数值。
对于(+ - * / ** % << >> | & ^) 的运算,我们也可以加入转换类型方法,把错误的数值转换。
<?phperror_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 error_log日志A non well formed numeric value encountered原因
- A non well formed numeric value encountered in 。。。
- thinkphp5 时间戳 A non well formed numeric value encountered
- TP5 提示 A non well formed numeric value encountered
- java读写excel时出现Cannot get a NUMERIC value from a STRING cell的解决方法
- php ip2long 出现负数原因及解决方法
- php ip2long 出现负数原因及解决方法
- php中出现“Call to a member function Execute() on a non-object”的问题
- php中出现“Call to a member function Execute() on a non-object”的问题
- PHP has encountered an Access Violation问题的解决方法总结
- Spring Memcached 使用incr 方法报cannot increment or decrement non-numeric value 解决方法
- Memcached做decr或incr操作时出现 CLIENT_ERROR cannot increment or decrement non-numeric value
- PHP出现 Warning: session_start()的解决方法-菜鸟学Ajax知识点
- Linux 安装编译PHP出现的问题及解决方法
- 出现类似'CListView' : is not a class or namespace name的原因及解决方法
- Android编译时出现aapt.exe finished with non-zero exit value 1错误的解决方法
- apt-get出现E:Encountered a section with no Package: header, ……的解决方法
- ESTJ职业规划,适合的工作类型及升职加薪指南
- 2017南宁现场赛E 存档
- Java集合(Unfinished-整理排版中)
- 基于Android官方Paging Library的RecyclerView分页加载框架
- Android软键盘遮挡的四种解决方案
- php 出现Warning: A non-numeric value encountered问题的原因及解决方法
- 阴影贴图1
- 【C++】<string> 与<string.h>、<cstring>的区别
- 面试感悟:3年工作经验java程序员应有的技能
- vb.net 教程 8-2 简单的SQL语言8
- HCL 模拟器安装注意
- Prim算法
- AXI总线简介
- 阴影贴图2