php反射应用示例

前端之家收集整理的这篇文章主要介绍了php反射应用示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

代码如下:
PHP
function custom(){
}

class custom{
public function index(){

}
}
print_r(get_define_position('custom'));

/**
* /
* @param string $name 函数名或者类名
* @return array
*/
function get_define_position($name){
$info = array();
if(class_exists($name)){
$ob = new ReflectionClass($name);
$info['class_'.$name]= array('file'=>$ob->getFileName(),'line'=>$ob->getStartLine());
}
if(function_exists($name)){
$ob = new ReflectionFunction($name);
$info['function_'.$name]= array('file'=>$ob->getFileName(),'line'=>$ob->getStartLine());
}
return $info;
}

原文链接:https://www.f2er.com/php/25063.html

猜你在找的PHP相关文章