PHP defines several constants in advance and provides a mechanism to define them at run time. Constants and variables are basically the same, and the difference is that constants must be defined with the Define function, and once a constant is defined, it cannot be redefined.
Pre-defined constants in PHP:
__file__
This default constant is the name of the PHP program file. If a reference file (include or require) is in the reference file, the constant is the reference file name, not the file name.
__line__
This default constant is the number of PHP program lines. If a reference file (include or require) is in the reference file, the constant is the row that refers to the file, not the file line that references it.
Php_version
This built-in constant is a version of the PHP program, such as ' 3.0.8-dev '.
Php_os
This built-in constant refers to the operating system name, such as ' Linux ', that executes the PHP parser.
TRUE
This constant is the truth (true).
FALSE
This constant is a pseudo value (false).
E_error
This constant refers to the nearest error.
E_warning
This constant refers to the nearest warning.
E_parse
This literal is a potential problem for parsing syntax.
E_notice
This constant is unusual but not necessarily wrong. For example, to access a variable that does not exist.
These e_ are the beginning of the constants, you can refer to the error_reporting () function, there are more relevant instructions.
You can define more constants with the Define function.
For example, define constants:
<?php
Define ("CONSTANT", "Hello world.");
Echo CONSTANT; Outputs "Hello world."
?>
With examples of __file__ and __line__
Php:
function Report_error ($file, $line, $message) {
echo "An error occured in $file to line $line: $message."
}
Report_error (__file__,__line__, "something went wrong!");
?>
My own wording:
?
$file = __file__;
$line = __line__;
Echo $file;
echo "<br><br>";
Echo $line;
echo "<br><br>";
Echo __file__;
echo "<br><br>";
Echo (__line__);
?>
ECHO constant with Echo (); Without echo ""