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

相关推荐
代码不停5 分钟前
网络原理——初识
开发语言·网络·php
BingoGo39 分钟前
使用 PHP 和 Raylib 也可以开发贪吃蛇游戏
后端·php
用户2018792831671 小时前
Android 混淆引发的反序列化问题浅析
android
00后程序员张1 小时前
iOS 性能优化的体系化方法论 从启动速度到渲染链路的多工具协同优化
android·ios·性能优化·小程序·uni-app·iphone·webview
游戏开发爱好者81 小时前
iPhone重启日志深度解析与故障代码诊断
android·ios·小程序·https·uni-app·iphone·webview
zwm_yy1 小时前
php8新增函数
php
007php0072 小时前
Redis面试题解析:Redis的数据过期策略
java·网络·redis·缓存·面试·职场和发展·php
Jtti2 小时前
IPv4与IPv6共存下的访问问题排查方法
开发语言·php
JaguarJack2 小时前
使用 PHP 和 Raylib 也可以开发贪吃蛇游戏
游戏·php·服务端