Magic constants

There are nine magical constants that change depending on where they are used. For example, the value of __LINE__ depends on the line that it's used on in your script. All these "magical" constants are resolved at compile time, unlike regular constants, which are resolved at runtime. These special constants are case-insensitive and are as follows:

PHP's magic constants
Name Description
__LINE__ The current line number of the file.
__FILE__ The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned.
__DIR__ The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory.
__FUNCTION__ The function name, or for anonymous functions.
__CLASS__ The class name. The class name includes the namespace it was declared in (e.g. Foo\Bar). When used in a trait method, __CLASS__ is the name of the class the trait is used in.
__TRAIT__ The trait name. The trait name includes the namespace it was declared in (e.g. Foo\Bar).
__METHOD__ The class method name.
__NAMESPACE__ The name of the current namespace.
ClassName::class The fully qualified class name.

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

News for PHP developers: Laravel 11 release

On March 12, 2024, the long-awaited version 11 of the Laravel framework was released, bringing with it a number of exciting new features and improvements for the PHP development community. ...

Mike94

Autor : Mike94
Category: PHP Magazin

Technical SEO remains relevant

Technical SEO - What is it anyway? Technical SEO refers to the optimization of the technical aspects of your website. The goal is clear! ...

admin

Autor : admin
Category: SEO & Online-Marketing

What's new in PHP 8.2.10

PHP 8.2.10 is one of the latest versions of PHP, which brings a number of improvements and new features. In this article we will discuss some of the outstanding new features and improvements in this version. ...

admin

Autor : admin
Category: Software-Updates

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial