Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Magic Constants in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 278
    Comment on it

    Hello Readers,

    PHP Magic Constants:

    There are many magic constants are available in PHP, but some magic constants are most important used in php, like LINE_, _DIR_, _FILE ,__CLASS__, __FUNCTION__etc. These constants are case-sensitive.

    Use of the magic constants are as follows:

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

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

    3) _FILE_ : This magic constant is used to indicate the full path of the file.

    4) _CLASS_ : This magic constant returns the class name.

    5) _FUNCTION_ : This magic constant returns the function name.

    6) _METHOD_ : This magic constant returns the function name.

    7) _NAMESPACE_ : This magic constant displays the namespace in which we are working.

      Example of the some magic constants are given below:

    <?php
    
    function const(){
    
    echo __LINE__
    echo __FILE__
    echo __DIR__
    echo __FUNCTION__
    echo __METHOD__
    } const(); ?>

    Output:

    3
    C:\xampp\htdocs\PHP-css\master.php
    C:\xampp\htdocs\PHP-css
    const
    const
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: