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) *** ** * ** ***

相关推荐
whysqwhw18 分钟前
OkHttp PublicSuffix包的后缀列表处理
android
yeziyfx1 小时前
kotlin中集合的用法
android·开发语言·kotlin
果子⌂1 小时前
Docker-构建镜像并实现LNMP架构
mysql·nginx·docker·容器·架构·php
tomcsdn312 小时前
SMTPman,smtp的端口号是多少全面解析配置
服务器·开发语言·php·smtp·邮件营销·域名邮箱·邮件服务器
EngZegNgi2 小时前
安卓应用启动崩溃的问题排查记录
android·crash·启动崩溃
火柴就是我3 小时前
每日见闻之Container Decoration
android·flutter
天枢破军3 小时前
【AOSP】解决repo拉取提示无法连接android.googlesource.com
android
whysqwhw3 小时前
OkHttp之AndroidPlatform类分析
android
XiaolongTu3 小时前
Kotlin Flow详述:从一个“卡顿”问题到线程切换的本质
android·面试
Kapaseker3 小时前
全网最详细的Compose Stable讲解,你一定要看
android