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

相关推荐
技术小丁3 分钟前
使用 PHP 和 PhpSpreadsheet 在 Excel 中插入图片(附完整代码)
后端·php
半桔21 分钟前
【IO多路转接】epoll 高性能网络编程:从底层机制到服务器实战
linux·运维·服务器·网络·php
下位子30 分钟前
『OpenGL学习滤镜相机』- Day5: 纹理变换与矩阵操作
android·opengl
一种乐趣1 小时前
PHP推荐权重算法以及分页
算法·php·推荐算法
撩得Android一次心动1 小时前
Android 四大组件——BroadcastReceiver(广播)
android·java·android 四大组件
努力学习的小廉1 小时前
初识MYSQL —— 复合查询
android·数据库·mysql
刘恒1234567891 小时前
Windows 10 docker 配置(PHP+Nginx+Mysql)(thinkphp5项目)环境
windows·docker·php
ii_best2 小时前
安卓/IOS工具开发基础教程:按键精灵一个简单的文字识别游戏验证
android·开发语言·游戏·ios·编辑器
JaguarJack2 小时前
PHP 开发中 你可能不知道的非常好用 PhpStorm 插件
后端·php
Digitally10 小时前
如何用5种实用方法将电脑上的音乐传输到安卓手机
android·智能手机·电脑