Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you give an example of how to use PHP __method__?

Tags:

methods

php

class

I am looking over some PHP code and I found some references to the PHP constant __METHOD__. I read the PHP documentation but all it says is

The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).

This isn't clear to me. Can anyone give an example or describe this in more detail?


2 Answers

__METHOD__ returns the name of the current class and method you are in when calling that constant.

http://php.net/manual/en/language.constants.predefined.php

__FUNCTION__ will only return the function name.

like image 76
mpm Avatar answered Feb 03 '26 14:02

mpm


echo __METHOD__."in".__FILE__." called";

You can use it for debug or log purpose.

like image 38
DonCallisto Avatar answered Feb 03 '26 12:02

DonCallisto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!