好好学习,东方不败。

做个努力的小伙。

  博客园  :: 首页  :: 新随笔  ::  ::  :: 管理
php反射应用示例。

代码如下:<?php

function custom(){
}
class custom{
   public function index(){
   }
 }
print_r(get_define_position('custom'));
 /**
  * /
  * @param  string $name  函数名或者类名
  * @return array       
  
*/ www.jbxue.com
 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;
 }
posted on 2014-02-25 13:43  snowfly123  阅读(271)  评论(0编辑  收藏  举报