The difference between PHP $_server[' Script_filename ' and __file__

Source: Internet
Author: User

Typically, PHP $_server[' script_filename ' and __file__ will return the full path (absolute path) and file name of the PHP file:

<?phpecho ' script_filename: ', $_server[' script_filename '];echo ' <br/> '; Echo ' __file__ is: ', __FILE__;//  Output?> in included Files

Copy the above test code to test.php and access the file (http://127.0.0.1/php/test.php) to get the following result:

Tip: In the Windows platform test, get the results as shown above there may be subtle differences in path separators.

$_server[' Script_filename ') differs from __file__

Although $_server[' Script_filename ' is very similar to __file__, there are subtle differences when files are included in include or require.

Copy the above test code to E:\web\html\php\common\inc.php and include the inc.php in the test.php file just now:

<?phpinclude ' common/inc.php ';? >

When you access the test.php file again, the output:

The difference between the two is that$_server[' script_filename ' reflects the absolute path and file name of the current executing program, and __file__ reflects the absolute path and file name of the original file (the contained file).

It can be understood that$_server[' script_filename ' is output only for the absolute path and file name of the executable files, regardless of which file is written.

__FILE__ write in which file, output the absolute path and file name of which file.

Reprinted: 53402477

The difference between PHP $_server[' Script_filename ' and __file__

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.