Home Tutorial Php Phpbasics Tutorial PHP Magic Constant


Share on Google+Share on Google+
PHP Magic Constant
Posted on: March 19, 2010 at 12:00 AM
In this tutorial we will study about magic constant, in PHP there are many magic constants are available,like _LINE_, _DIR_, _FILE_ etc. These constants are case-sensitive

PHP Magic Constants:

In PHP there are various predefined constants, but many of the constants are created by various extensions and could be implemented only when those extensions are available. These extensions could be available either by dynamic loading or they have been compiled before.

There are many magical constants are available in PHP, but seven magical constants are most important, like _LINE_, _DIR_, _FILE_ etc. These constants are case-sensitive. Use of the magic constants are as follows:

1) __LINE__: This constant is used to indicate the current line number of the file.

2) __DIR__ :  This constant is used to indicate the current directory in which the file is present

3) __FILE__ : This constant is used to indicate the full path of the file

4) __CLASS__ : Returns the class name

5) __FUNCTION__ : Returns the function name

6) __METHOD__ : Returns the function name

7) __NAMESPACE__ : Displays the namespace in which we are working.




function fun_co(){

echo __LINE__."<BR/>";

echo __FILE__."<BR/>";

echo __DIR__."<BR/>";


ECHO __METHOD__."<BR/>";







Related Tags for PHP Magic Constant:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 19, 2010

Recommend the tutorial

Advertisements Advertisements