zl程序教程

您现在的位置是:首页 >  后端

当前栏目

php反射应用示例

2023-06-13 09:15:18 时间

复制代码代码如下:


<?php
functioncustom(){
}

classcustom{
   publicfunctionindex(){

   }
 }
print_r(get_define_position("custom"));

 /**
 */
 *@param string$name 函数名或者类名
 *@returnarray      
 */
 functionget_define_position($name){
   $info=array();
   if(class_exists($name)){
     $ob=newReflectionClass($name);
     $info["class_".$name]=array("file"=>$ob->getFileName(),"line"=>$ob->getStartLine());
   }
   if(function_exists($name)){
     $ob=newReflectionFunction($name);
     $info["function_".$name]=array("file"=>$ob->getFileName(),"line"=>$ob->getStartLine());
   }
   return$info;
 }