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']);
}

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

链接 讲解


相关推荐
疯华整猫8 分钟前
否决 Flutter 提案那天,我发现自己也说不清 Framework 管什么
android
笑容掩饰我的失落17 分钟前
区块链从小白到精通(七):Solidity 语法精讲——数据类型、函数、修饰器与事件
算法·区块链·php·智能合约·哈希算法
传奇开心果编程13 小时前
【Flutter踩坑排雷】第25课:ScrollController 误用坑|跳转失效、监听泄漏与“控制器未附加”
android·flutter·ios·移动开发·跨平台·dart·声明式ui
慕容雪_16 小时前
Capacitor8-Android打包完整手册
android·打包·capacitor
寂寞的船17 小时前
【Unity Bug挑战】第12期 Awaitable 二次 await 死锁之谜 —— 为什么同一个异步操作等两次就卡死?
unity·c#·游戏引擎·bug
阿杰m20 小时前
Android源码第十三章:Bluetooth——沿一次发现走到控制器
android
booboosui20 小时前
派活给另一个 AI:前后两次文件夹快照,就是交付清单
android
笑容掩饰我的失落21 小时前
区块链从小白到精通(八):从零实现一个标准 ERC-20 代币(完整可运行代码)
算法·区块链·php·智能合约·哈希算法
普通人61 天前
MySQL_FIND_IN_SET函数详解
android·数据库·mysql
好的佩奇2 天前
Dart 之集合元素
android·flutter·dart