PHP provides a large number of predefined constants to any script it runs.
However, many constants are defined by different extension libraries and will only appear when these extension libraries are loaded, or after dynamic loading, or have been included during compilation.
1. __LINE__
The current line number in the file
<?php header("Content-type: text/html; charset=utf-8");//设置编码 echo '这是第 “ ' . __LINE__ . ' ” 行'; //查看第几行 ?>
2. __FILE__
The full path and file name of the file. If used within an included file, returns the name of the included file.
Since PHP 4.0.2, __FILE__ always contains an absolute path (or the resolved absolute path if it is a symbolic link), while versions before that sometimes contained a relative path
<?php header("Content-type: text/html; charset=utf-8");//设置编码 echo '该文件位于 " ' . __FILE__ . ' " '; //查看路径 ?>
3. __DIR__
The directory where the file is located. If used within an included file, returns the directory where the included file is located.
It is equivalent to dirname(__FILE__). Directory names do not include the trailing slash unless they are the root directory. (New in PHP 5.3.0)
<?php header("Content-type: text/html; charset=utf-8");//设置编码 echo '该文件位于 " ' . __DIR__ . ' " '; ?>
__FUNCTION__
<?php function test() { echo '函数名为:' . __FUNCTION__ ; } test(); ?>5.
__CLASS__
<?php class test { function _print() { echo '类名为:' . __CLASS__ . "<br>"; echo '函数名为:' . __FUNCTION__ ; } } $t = new test(); $t->_print(); ?>
__METHOD__
<?php function test() { echo '函数名为:' . __METHOD__ ; } test(); ?>