PHP Beginner's Guide to Magic Variables

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

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


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)


##4.

__FUNCTION__

5.

__CLASS__


The name of the class (newly added in PHP 4.3.0). Since PHP 5 this constant returns the name of the class when it was defined (case sensitive).

In PHP 4 this value is always lowercase. The class name includes the scope in which it is declared (e.g. Foo\Bar). Note that since PHP 5.4 __CLASS__ also works for traits. When used in a trait method, __CLASS__ is the name of the class that calls the trait method

"; echo '函数名为:' . __FUNCTION__ ; } } $t = new test(); $t->_print(); ?>


6.

__METHOD__


Returns the name of the method when it was defined (case sensitive)


Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!