_ File _: a PHP magic constant

Source: Internet
Author: User

_ File _: a PHP magic constant. It returns the complete path and file name of the currently executed PHP script, including an absolute path.

1) The dirname (_ file ___) function returns the path where the script is located.
For example, file B. php contains the following content:
<? PHP $ basedir = dirname (_ file _);?>
If B. php is referenced by the. php file require or include in another directory. The content of the variable $ basedir is still the path of the folder where B. php is located. Instead of the directory where the. php file is located.

2) dirname (_ file _) usually returns a directory structure from the current directory of the file to the root directory of the system. The current file name is not returned. Dirname (_ file _) may also return a. (current directory) [The reason is that the B. php file is in the default web directory of HTTP. conf or PHP to configure the development environment]

Several PHP "Magic constants"
Description
The current row number in the _ line _ file.
The complete path and file name of the _ file. If it is used in a include file, the include file name is returned. Starting from PhP 4.0.2, __file _ always contains an absolute path, while earlier versions sometimes contain a relative path.

For example, if a. php contains the _ file _ in B. php and the _ file _ in A. php are different values.

In particular, no matter who contains B. php, the value of _ file _ will never change to the absolute physical path of B. php itself.
 
_ Function name (New in PHP 4.3.0 ). Starting from PHP 5, this constant returns the name (case sensitive) when the function is defined ). In PHP 4, the value is always lowercase letters.
_ Class name (New in PHP 4.3.0 ). Starting from PHP 5, this constant returns the name (case sensitive) when the class is defined ). In PHP 4, the value is always lowercase letters.
_ Method _ class method name (New PHP 5.0.0 ). Returns the name (case sensitive) when the method is defined ).

We found that _ file _ is a magic constant provided by PHP. It always returns the absolute path of the file parsed by PHP.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.