Home >Backend Development >PHP Tutorial >php reflection application example

php reflection application example

高洛峰
高洛峰Original
2016-12-23 12:51:54969browse

<?php
function custom(){
}
class custom{
   public function index(){
   }
 }
print_r(get_define_position(&#39;custom&#39;));
 /**
  * /
  * @param  string $name  函数名或者类名
  * @return array       
  */
 function get_define_position($name){
    $info = array();
    if(class_exists($name)){
      $ob = new ReflectionClass($name);
      $info[&#39;class_&#39;.$name]= array(&#39;file&#39;=>$ob->getFileName(),&#39;line&#39;=>$ob->getStartLine());
    }
    if(function_exists($name)){
      $ob = new ReflectionFunction($name);
      $info[&#39;function_&#39;.$name]= array(&#39;file&#39;=>$ob->getFileName(),&#39;line&#39;=>$ob->getStartLine());
    }
    return $info;
 }

php reflection application example

For more articles related to PHP reflection application examples, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn