PHP - 遇到的Bug - 总结

BUG记录1

问题 除数为0,不符合规则

问题描述

php 复制代码
// 报错信息
DivisionByZeroError:is thrown when an attempt is made to divide a number by zero.

// example
public class Example
{
   public static void Main()
   {
      int number1 = 3000;
      int number2 = 0;
      try {
         Console.WriteLine(number1 / number2);
      }
      catch (DivideByZeroException) {
         Console.WriteLine("Division of {0} by zero.", number1);
      }
   }
}

解决方法 运行前判断 如果除数为0,则不要计算

链接


BUG记录2

问题 参数不符合

问题描述

php 复制代码
参数要求是数组,实际却是字符串
implode(): Argument #1 ($pieces) must be of type array, string given in implode()

// 出错前代码
$variables['classes'] = implode(' ', $variables['classes_array']);

// 修改方法
if(is_array($variables['classes_array']))
{
$variables['classes'] = implode(' ', $variables['classes_array']);
}
else if (is_string($variables['classes_array']))
{
$variables['classes'] = implode(' ', (array)$variables['classes_array']);
// 等价于
$variables['classes'] = explode(' ', $variables['classes_array']);
}

解决方法 运行前判断参数类型

链接 讲解


相关推荐
xingyuzhisuan7 小时前
网络 Token 常见故障原理,基础排查科普
运维·服务器·网络·php
巴博尔8 小时前
UNIAPP中NVUE页面 动画
android·前端·javascript·ios·uni-app
z落落8 小时前
C#String字符串
开发语言·c#·php
abc_ABC123A12 小时前
flutter开发安卓APP所需搭建的环境
android
xq952714 小时前
Google 授权登录 V2 接入文档 王者归来
android
李少兄14 小时前
MySQL分页重复问题深度剖析
android·数据库·mysql
鬼才血脉15 小时前
Idea使用Tomact运行项目,控制台输出中文乱码
tomcat·bug
fiveym15 小时前
Debian 12 PXE 安装报错:Bad archive mirror 复合型故障排查全记录
运维·服务器·debian·php
_李小白16 小时前
【android opencv学习笔记】Day 24: 最大稳定极值区域
android·opencv·学习
问心无愧051317 小时前
ctf show web入门257
android·前端·笔记