return new static
<?php
class A{
}
class B extends A{
public static function foo () {
echo 'new self: ';
var_dump(new self());
echo '<br>new parent: ';
var_dump(new parent());
echo '<br>new static: ';
var_dump(new static());
}
}
class C extends B{
}
c::foo();
===========================
output:
//new self: object(B)#1 (0) { }
//new parent: object(A)#1 (0) { }
//new static: object(C)#1 (0) { }
区别:其作用的指向范围
self : 方法所在当前类(非调用类)
parent:方法所在类的上级基类(非调用类)
static:方法调用类
glob
glob (string $pattern , int $flags = 0): array
寻找与模式匹配的文件路径
array_flip
交换数组中的键和值,若同一值多次出现,则最后一个键名将作为它的值,其他键会被抛弃
fn 短闭包函数
示例:
$posts = [....];
$ids = array_map( fn($post) => $post->id,$posts);
之前的用法:
$ids = array_map(function ($post){
return $post->id;
},$posts);
总结: 在php7.4可用,以fn关键字开头,只包含一个表达式,return关键字可省略
set_exception_handler
设置用户自定义的异常处理函数 ,用于处理没有被 try…catch… 捕捉到的异常
多维数组排序
$numArray = [1,3,9,5];
array_multisort($numArray,SORT_DESC,$list);
numArray
排序参考列,对该列进行排序,随后应用到整个数据SORT_DESC
降序排序list
待排序数据
get_class_vars 获取类的公有属性
注意:仅能获取公有属性,私有和受保护的属性需要通过反射来获取
phpstorm快捷键
ctrl shift +/-
一键折叠和展开所有代码