Home  >  Article  >  Backend Development  >  What does the __file__ attribute mean in php mysql

What does the __file__ attribute mean in php mysql

青灯夜游
青灯夜游Original
2022-02-17 14:27:462251browse

In php mysql, "__file__" means "get file path". It is a system predefined constant that can get and return the absolute path of the current file (including the file name). If it is Symbolic link is the resolved absolute path.

What does the __file__ attribute mean in php mysql

The operating environment of this tutorial: windows7 system, PHP7.1&&mysql8 version, DELL G3 computer

"__file__" is a magic constant (system preset Defined constant), it will return the full path and file name of the currently executing PHP script, that is, the absolute path (including the file name).

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 .

Example:

<?php
header("Content-type:text/html;charset=utf-8");
echo "当前文件的路径:".__FILE__;
?>

What does the __file__ attribute mean in php mysql

Extended knowledge:

There are magic constants in PHP Eight, as follows:

  • __LINE__: The current line number in the file;

  • __FILE__: The absolute path of the current file (including the file name);

  • __DIR__: The absolute path of the current file (excluding the file name), equivalent to dirname(__FILE__);

  • __FUNCTION__ : The name of the current function (or method);

  • __CLASS__: The current class name (including the scope or namespace of the class);

  • __TRAIT__: The current trait name (including the scope or namespace of the trait);

  • __METHOD__: The current method name (including the class name);

  • __NAMESPACE__: The name of the namespace of the current file.

Note: Unlike predefined constants, magic constants are not case-sensitive.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does the __file__ attribute mean in php mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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