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->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>
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
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD

Hot tools Tags

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use classes and methods in Python

Replace the class name of an element using jQuery

How SpringBoot encrypts and protects class files through custom classloader

Methods of predefined Class objects in java

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