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

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

链接 讲解


相关推荐
姜太小白39 分钟前
【Linux】df -h 卡住问题的通用排查与解决方案总结
linux·运维·php
码农coding3 小时前
android12 systemUI 之锁屏
android
圆山猫3 小时前
[Virtualization](三):RISC-V H-extension 与 Guest 执行模式
android·java·risc-v
狗凯之家源码网3 小时前
短剧系统搭建实战:源码功能与商业变现效果全景展示
开发语言·php
爱笑鱼4 小时前
Binder(七):getCallingUid() 读到的是谁?clearCallingIdentity() 又清掉了什么?
android
连续讨伐5 小时前
php小结
开发语言·php
2601_965798476 小时前
MTDb Movie & TV Database Script Setup, Caching, and SEO Guide
linux·服务器·数据库·php
小小代码狗8 小时前
PHP 常用函数与变量参考文档
开发语言·安全·php
看昭奚恤哭9 小时前
LWIP TCP滑动窗口为TCP ZeroWindow的解决方法
网络·tcp/ip·php
AC赳赳老秦9 小时前
CSDN 技术社区数据采集:OpenClaw 抓取公开技术热帖,生成领域技术热点周报
java·大数据·前端·数据库·python·php·openclaw