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

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

Jun 13, 2016 pm 01:42 PM
class function quot this

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-&gt;v;<br>   }<br>}<br><br>class c extends a<br>{<br>   function d(){<br>      $this-&gt;v = __FUNCTION__;<br>      $this-&gt;b();<br>   }<br>}<br>$c = new c();<br>$c-&gt;d();
<br><font color="#e78608">------解决方案--------------------</font><br>嗯,又学到东西了,3Q了 <div class="clear">
                 
              
              
        
            </div>
Copy after login
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use classes and methods in Python How to use classes and methods in Python Apr 21, 2023 pm 02:28 PM

How to use classes and methods in Python

What does function mean? What does function mean? Aug 04, 2023 am 10:33 AM

What does function mean?

Replace the class name of an element using jQuery Replace the class name of an element using jQuery Feb 24, 2024 pm 11:03 PM

Replace the class name of an element using jQuery

What does class mean in python? What does class mean in python? May 21, 2019 pm 05:10 PM

What does class mean in python?

How SpringBoot encrypts and protects class files through custom classloader How SpringBoot encrypts and protects class files through custom classloader May 11, 2023 pm 09:07 PM

How SpringBoot encrypts and protects class files through custom classloader

Methods of predefined Class objects in java Methods of predefined Class objects in java Jul 01, 2023 pm 06:41 PM

Methods of predefined Class objects in java

Detailed explanation of PHP Class usage: Make your code clearer and easier to read Detailed explanation of PHP Class usage: Make your code clearer and easier to read Mar 10, 2024 pm 12:03 PM

Detailed explanation of PHP Class usage: Make your code clearer and easier to read

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决

See all articles