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

相关推荐
阿巴斯甜7 小时前
ARouter
android
Andya_net9 小时前
MySQL | MySQL 8.0 权限管理实践-精确赋予库、表只读等权限
android·数据库·mysql
Cyber4K9 小时前
【Python专项】进阶语法-系统资源监控与数据采集(1)
开发语言·python·php
阿巴斯甜9 小时前
Map
android
巫山老妖9 小时前
鹅厂十年:三段式技术成长复盘
android·人工智能·程序员
Le_ee9 小时前
ctfweb:php/php短标签/.haccess+图片马/XXE
开发语言·前端·php
阿巴斯甜9 小时前
List集合
android
ooseabiscuit10 小时前
Laravel6.x核心优化与特性全解析
android·开发语言·javascript
阿巴斯甜11 小时前
Kotlin 协程 Coroutine
android
Jomurphys12 小时前
Compose 适配 - 通过 UiMediaScope 获取设备信息
android·compose