The new Magic constant DIR in PHP5.3

Source: Internet
Author: User
The new magic constant DIR in PHP5.3 we know that PHP provides a magic constant (magic constant) _ FILE __, which is used to point to the currently executed PHP script.

However, PHP does not directly provide constants in the directory where the script is located. That is to say, if we want to get the directory where the current PHP script is located, we need to use the dirname () function:

<? Php

$ Dir = dirname (_ FILE __);

?>

In PHP5.3, a new constant _ DIR __is added to point to the directory where the currently executed PHP script is located.

For example, the current php file is/www/website/index. php.

Then _ FILE _ is equal to '/www/website/index. php'

The value of _ DIR _ is equal to '/www/website'

To include files in the current file directory or subdirectory, you can directly use:

Require_once _ DIR _. '/path/to/test. inc. php';?>

This article is reprinted article ---- Original address http://blog.csdn.net/haohappy2004/article/details/2114808

Permanent Address: http://blog.it985.com/15611.html

This article is from the IT985 blog. please indicate the source and relevant links when reprinting.

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.