424   PHP

一,魔术变量

1,__NAMESPACE__
显示命名空间

2,__LINE__
显示当前行数

3,__FILE__
当前文件全路径,包括目录和文件名

4,__DIR__
当前文件目录

5,__CLASS__
显示类名

6,__FUNCTION__
显示方法名

7,__METHOD__
显示类名和方法名

 

 

二,示例代码

namespace test;
class test{
	public function __construct() {
		echo 'initializing test',"\n";
	}
	
	public function getClassName(){
		return __CLASS__;
	}
	
	public function getFunctionName(){
		return __FUNCTION__;
	}
	
	public function getMethodName(){
		return __METHOD__;
	}
	
}


$test = new test();

echo '__NAMESPACE__',"\n";
echo __NAMESPACE__;

echo "\n";
echo '__LINE__',"\n";
echo __LINE__;

echo "\n";
echo '__FILE__',"\n";
echo __FILE__;

echo "\n";
echo '__DIR__',"\n";
echo __DIR__;

echo "\n";
echo '__CLASS__',"\n";
echo $test->getClassName();
echo "\n";
echo '__FUNCTION__',"\n";
echo $test->getFunctionName();
echo "\n";
echo '__METHOD__',"\n";
echo $test->getMethodName();

 

三,测试结果

C:\Users\luckybird\Desktop\test>php test.php
initializing test
__NAMESPACE__
test
__LINE__
30
__FILE__
C:\Users\luckybird\Desktop\test\test.php
__DIR__
C:\Users\luckybird\Desktop\test
__CLASS__
test\test
__FUNCTION__
getFunctionName
__METHOD__
test\test::getMethodName




Leave a Reply

Your email address will not be published. Required fields are marked *