🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## empty为true的表达式 ~~~ empty(null); empty(0); empty('0'); empty(''); empty(false); empty([]); empty($not_exists_var);//未定义的变量 ~~~ ## empty为false的表达式 ~~~ $exists_var = 'abc'; $a[] = empty($exists_var); $a[] = empty($exists_var[0]); $a[] = empty($exists_var[0.5]); $a[] = empty($exists_var['0']); ~~~ ## NULL 合并运算符 ~~~ //当$username未定义,或者为null,值为 'nobody' $username = $username ?? 'nobody'; //等价 $username = isset($username) ? $username : 'nobody'; //当$username为空(empty()返回true) $username = $username ?: 'nobody'; //等价 $username = empty($username) ? $username : 'nobody'; ~~~ ## 返回带命名空间的完整的类名 ~~~ echo BaseController::class; //返回 "app\\BaseController" ~~~ ## 获取某个文件夹下的文件 ~~~ $files = glob($filePath . '*.php'); ~~~ ## new self与 new static的区别 self指向的是当前方法存在的这个类,也就是父类。static指向的是最终那个子类。 ~~~ class Parent { public static function getParent() { return new self; } public static function getChild() { return new static; } } class Son extends Parent { } var_dump(Son::getParent(), PHP_EOL);//object(Parent)#1 (0) {} var_dump(Son::getChild(), PHP_EOL);//object(Son)#1 (0) {} ~~~ ## self::ClassName 与 static::ClassName 的区别 self指向的是当前方法存在的这个类,也就是父类。static指向的是最终那个子类。 ~~~ class Parent { public static function getParent() { return self::class; } public static function getChild() { return static::class; } } class Son extends Parent { } echo Son::getParent(), PHP_EOL;//parent echo Son::getChild(), PHP_EOL;//Son ~~~ ## 为什么字符集不选择utf8,排序规则不使用utf8\_general\_ci 采用utf8编码的MySQL无法保存占位是4个字节的Emoji表情。为了使后端的项目,全面支持客户端输入的Emoji表情,升级编码为utf8mb4是最佳解决方案。对于JDBC连接串设置了characterEncoding为utf8或者做了上述配置仍旧无法正常插入emoji数据的情况,需要在代码中指定连接的字符集为utf8mb4。