PHP Magic Constants

0
2χλμ.

PHP Predefined Constants

PHP has nine predefined constants that change value depending on where they are used, and therefor they are called "magic constants".

These magic constants are written with a double underscore at the start and the end, except for the ClassName::class constant.


Magic Constants

Here are the magic constants, with descriptions and examples:

Constant Description  
__CLASS__ If used inside a class, the class name is returned. Try it »
__DIR__ The directory of the file. Try it »
__FILE__ The file name including the full path. Try it »
__FUNCTION__ If inside a function, the function name is returned. Try it »
__LINE__ The current line number. Try it »
__METHOD__ If used inside a function that belongs to a class, both class and function name is returned. Try it »
__NAMESPACE__ If used inside a namespace, the name of the namespace is returned. Try it »
__TRAIT__ If used inside a trait, the trait name is returned. Try it »
ClassName::class Returns the name of the specified class and the name of the namespace, if any. Try it »

Note:

The magic constants are case-insensitive, meaning __LINE__ returns the same as __line__.

Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
άλλο
PHP Functions
The real power of PHP comes from its functions. PHP has more than 1000 built-in functions, and...
από PHP Tutorial 2024-05-17 07:53:06 0 2χλμ.
άλλο
PHP for Loop
The for loop - Loops through a block of code a specified number of times. The PHP...
από PHP Tutorial 2024-05-17 07:49:43 0 2χλμ.
άλλο
PHP Strings
A string is a sequence of characters, like "Hello world!". Strings Strings in PHP are...
από PHP Tutorial 2024-05-17 07:28:17 0 2χλμ.
άλλο
PHP - Escape Characters
Escape Character To insert characters that are illegal in a string, use an escape character. An...
από PHP Tutorial 2024-05-17 07:32:36 0 3χλμ.
άλλο
PHP Constants
Constants are like variables, except that once they are defined they cannot be changed or...
από PHP Tutorial 2024-05-17 07:39:53 0 2χλμ.