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

解决方法\] 运行前判断参数类型 \[链接\] [讲解](https://www.drupal.org/project/drupal/issues/3310364) *** ** * ** ***

相关推荐
ヽ格式化16 分钟前
一文读懂栈与堆:从生活例子到Golang/PHP内存管理实践
golang·php·生活
lichong9511 小时前
XLog debug 开启打印日志,release 关闭打印日志
android·java·前端
c***97981 小时前
PHP在内容管理中的模板引擎
开发语言·php
用户69371750013841 小时前
14.Kotlin 类:类的形态(一):抽象类 (Abstract Class)
android·后端·kotlin
Q_Q5110082851 小时前
python+django/flask的情绪宣泄系统
spring boot·python·pycharm·django·flask·node.js·php
用户7227868123441 小时前
PHP Fiber 优雅协作式多任务
php
火柴就是我1 小时前
NekoBoxForAndroid 编译libcore.aar
android
Kaede63 小时前
MySQL中如何使用命令行修改root密码
android·mysql·adb
青茶3603 小时前
ThinkCMF是一个开源的内容管理框架
php·cms·thinkphp
明君879974 小时前
Flutter 图纸标注功能的实现:踩坑与架构设计
android·ios