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

php reflection application example

高洛峰
Release: 2023-03-04 07:40:01
Original
965 people have browsed it

<?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;
 }
Copy after login

php reflection application example

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template