PHP Magic Constants

0
5K

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__.

Zoeken
Categorieën
Read More
Other
PHP Arrays
An array stores multiple values in one single variable: ExampleGet your own PHP Server $cars...
By PHP Tutorial 2024-05-17 07:53:31 0 6K
Other
PHP Nested if Statement
Nested If You can have if statements inside if statements, this is...
By PHP Tutorial 2024-05-17 07:47:26 0 4K
Other
الثورة البلوكتشين وتحولاتها في الصناعات المختلفة
مقدمة: شهدت تقنية البلوكتشين ثورة هائلة في السنوات الأخيرة، حيث أصبحت لديها القدرة على تغيير...
By MOHAMED ATTALLAH 2024-05-14 14:03:03 0 7K
Other
PHP Continue
The continue statement can be used to jump out of the current iteration of a loop, and...
By PHP Tutorial 2024-05-17 07:52:32 0 4K
Other
PHP Constants
Constants are like variables, except that once they are defined they cannot be changed or...
By PHP Tutorial 2024-05-17 07:39:53 0 8K
Sociallez https://sociallez.com