BUG记录1
[问题] 除数为0,不符合规则
[问题描述]
// 报错信息
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
[问题] 参数不符合
[问题描述]
参数要求是数组,实际却是字符串
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']);
}
[解决方法] 运行前判断参数类型
[链接] 讲解