New magic constants in PHP 5.3__DIR___PHP Tutorial

WBOY
Release: 2016-07-13 17:37:03
Original
875 people have browsed it

We know that PHP provides a magic constant (magic constant) __FILE__, which is used to point to the currently executing PHP script. But PHP does not directly provide constants for 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:

$dir =dirname(__FILE__);

?>

In PHP5.3, a new constant __DIR__ is added, pointing to the directory where the currently executed PHP script is located.

For example, the currently executed PHP file is /www/website/index.php

Then __FILE__ is equal to /www/website/index.php

And __DIR__ is equal to /www/website

Now we want to include files in the current file directory or subdirectory, we can use it directly:

require_once __DIR__ ./path/to/test.inc.php;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486617.htmlTechArticleWe know that PHP provides a magic constant (magic constant) __FILE__, which is used to point to the currently executing PHP script. But PHP does not directly provide constants for the directory where the script is located. That is to say...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!