【每日函数】每日函数(2021.08.22)
一梦千年系列
今日函数
interface_exists
、is_a
、is_subclass_of
、method_exists
、property_exists
、trait_exists
interface_exists1
检查接口是否被定义
- 说明
interface_exists(string $interface_name, bool $autoload = true) : bool
- 参数
interface_name
接口名字
autoload
是否自动加载
- 返回值
如果已经定义返回true,否则返回false
is_a2
对象属于该类,或者该类是对象的父类
- 说明
is_a(object $obj, string $class_name, bool $allow_string = false) : bool
- 参数
obj
对象或者类名
class_name
类名称
allow_string
我也不清楚这个参数的用意
- 返回值
如果obj属于class_name,或者class_name是obj的父类则返回true,否则返回false
is_subclass_of3
对象属于该类,或者该类是对象的父类
- 说明
is_subclass_of(object $obj, string $class_name) : bool
- 参数
obj
对象或者类名
class_name
类名称
- 返回值
如果obj所属类是class_name的子类则返回true,否则返回false
method_exists4
检查类或者对象中的方法是否存在
- 说明
method_exists(mixed $obj, string $method_name) : bool
- 参数
obj
对象或者类名
method_name
方法名
- 返回值
如果此方法存在则返回true,否则返回false
property_exists5
检查对象或者类中属性是否存在
- 说明
property_exists(mixed $obj, string $property) : bool
- 参数
obj
对象或者类
property
属性
- 返回值
如果对象或者类中存在属性,则返回true,否则返回false
trait_exists6
检查trait是否定义
- 说明
trait_exists(string $trait_name, bool $autoload = true) : bool
- 参数
trait_name
trait名称
autoload
是否自动加载
- 返回值
如果trait已经定义则返回true,否则返回false