__METHOD__ and __FUNCTION__
Let me clarify your doubt..
First I will explain about CLASS & OBJECT(what is the difference..)
Then I will clarify about FUNCTION & METHOD(what is the difference..)
talking about Class :: It is a your logical implementation..
object :: It is a instance of your class (instance ~ COPY ~ clone ~ ...)
when you are using --NEW-- operator ---> you are creating an OBJECT (nothing but the COPY) OF YOUR CLASS.
CLASS =============> ~NEW~ =======> OBJECT (New Copy of your class..) similarly
FUNCTION ==========> ~NEW~ =======> METHOD (Belongs to Object not Class)
Class is the program you are writing while object is the copy of your class that is executing..
class resides in ROM(permanent) where as object resides in RAM(temporary memory area..)
& when you are declaring an function as static it belongs only to class not to object & you can call the same(static function) by using ClassName::staticFunctionName()
That is why there is no existence of STATIC_METHOD Rather STATIC_FUNCTION !!!
code example::
<?php
class Dog extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index($params = '') {
}
private $name = 'dog';
public static function name() {
echo 'Inside static function & inside class' . '<br>';
echo __METHOD__ . '<br>';
echo __FUNCTION__ . '<br>';
}
public function test2() {
echo 'Inside NON STATIC function & inside class' . '<br>';
echo __FUNCTION__ . '<br>';
echo __METHOD__ . '<br>';
}
}
function test() {
echo 'Inside NON STATIC function & OUTSIDE class' . '<br>';
echo __FUNCTION__ . '<br>';
echo __METHOD__ . '<br>';
}
Dog::name();
test();
$somevar = new Dog;
$somevar->test2();
OUTPUT::
Inside static function & inside class
Dog::name //Class::function
name
Inside NON STATIC function & OUTSIDE class
test
test
Inside NON STATIC function & inside class
test2
Dog::test2 //Object::method
IN Your case as you are using METHOD IN static context it showing the class name if the it would be a non static(Simple Function) it would show only function name only..
"Method" is basically just the name for a function within a class (or class function). Therefore __METHOD__
consists of the class name and the function name called (dog::name
), while __FUNCTION__
only gives you the name of the function without any reference to the class it might be in.
When __METHOD__
is called outside of a class it's the same as __FUNCTION__
because there is no class part to be used as a prefix. You can use __METHOD__
outside of a class because it's a magic constant and they're always available (at worst case they will return empty string).
http://php.net/manual/en/language.constants.predefined.php
in every programming language.. Method always corresponds to Object. Method <==> Object while Function always corresponds to both class & Object(Static Function).
and finally there is no existence of Static Method
&
In this case..
METHOD => includes class name FUNCTION => Only refers to function name
if any clarification contact me..