Several commonly used magic constants in PHP

  • 2020-05-12 02:23:57
  • OfStack

There are seven magic constants whose values change depending on where they are in the code. For example, the value of s = s = s = s = s depends on the line it is on in the script. These special constants are case insensitive, as follows: The name of the instructions __LINE__ The current line number in the file. __FILE__ The full path and file name of the file. If used in an included file, the included file name is returned. Starting with PHP 4.0.2, s/s 4en__ will always contain one absolute path (if it is a symbolic join, then the parsed one), whereas previous versions will sometimes contain one relative path. __DIR__ The directory in which the files are located. If used in an included file, the directory in which the included file is located is returned. It is equivalent to dirname(s) 7en__. Unless it is the root directory, the directory name does not include a trailing slash. (new in PHP 5.3.0) = __FUNCTION__ Function name (PHP 4.3.0 plus). This constant returns the name (case sensitive) of the function when it was defined, starting with PHP 5. In PHP 4 the value is always lowercase. __CLASS__ The name of the class (PHP 4.3.0 plus). This constant returns the name (case sensitive) of the class when it was defined, starting with PHP 5. In PHP 4 the value is always lowercase. __METHOD__ The method name of the class (PHP 5.0.0). Returns the name (case sensitive) when the method was defined. __NAMESPACE__ The name of the current namespace (case sensitive). This constant is defined at compile time (PHP 5.3.0 added)

Related articles: