PHP - 遇到的Bug - 总结

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

BUG记录1
[问题] 除数为0不符合规则
[问题描述]

// 报错信息
DivisionByZeroErroris 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
[问题] 参数不符合
[问题描述]

参数要求是数组,实际却是字符串
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']);
}

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


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: php

“PHP - 遇到的Bug - 总结” 的相关文章