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

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

[链接] 讲解


相关推荐
与衫1 小时前
掌握嵌套子查询:复杂 SQL 中 * 列的准确表列关系
android·javascript·sql
Eternal-Student2 小时前
everyday_question dq20240731
开发语言·arm开发·php
zhangphil4 小时前
Windows环境Apache httpd 2.4 web服务器加载PHP8:Hello,world!
php·apache·httpd
500了7 小时前
Kotlin基本知识
android·开发语言·kotlin
人工智能的苟富贵8 小时前
Android Debug Bridge(ADB)完全指南
android·adb
芒果作者12 小时前
dcatadmin 自定义登录页面
php
小雨cc5566ru13 小时前
uniapp+Android面向网络学习的时间管理工具软件 微信小程序
android·微信小程序·uni-app
bianshaopeng14 小时前
android 原生加载pdf
android·pdf
hhzz14 小时前
Linux Shell编程快速入门以及案例(Linux一键批量启动、停止、重启Jar包Shell脚本)
android·linux·jar
火红的小辣椒15 小时前
XSS基础
android·web安全