Home  >  Article  >  Backend Development  >  php如保得到类名和方法名?该如何处理

php如保得到类名和方法名?该如何处理

WBOY
WBOYOriginal
2016-06-13 13:42:31814browse

php如保得到类名和方法名?
class a{
function b{
//如果在这里打印出a_b呢?
}
}

------解决方案--------------------
class a{
function b{
 echo __CLASS__ . "_" . __METHOD__;
}
}
------解决方案--------------------
可以尝试这样

PHP code

class a{
    function  b($functionName){   
        echo get_class($this).'_'.$functionName;
    }   
} 

class   c   extends   a 
{ 
    function   d(){ 
       $this->b(__FUNCTION__); 
    } 
}
$c = new c();
$c->d();
<br><font color="#e78608">------解决方案--------------------</font><br>不用参数也可以的<br>class a{<br>   var $v = '';<br>   function b(){<br>       echo "<br>" . get_class($this).'_'.$this->v;<br>   }<br>}<br><br>class c extends a<br>{<br>   function d(){<br>      $this->v = __FUNCTION__;<br>      $this->b();<br>   }<br>}<br>$c = new c();<br>$c->d();
<br><font color="#e78608">------解决方案--------------------</font><br>嗯,又学到东西了,3Q了 <div class="clear">
                 
              
              
        
            </div>
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