Learn Magic Constants

These are predefined constants and can be changed  upon their usage . These start with double underscore (__)  and end with same .

These are same as predefined constants .Because they can change values , they are magic constant.

See someconstants see below: 


NameDescription
__FILE__It define the full path with filename
__LINE__Signifies full path and record name of the file. In case it is used inside an include, name of incorporated file is returned.
__FUNCTION__Symbolizes full directory path from the file. Equivalent to dirname(__file__). It will not have a walking slash unless it is a root directory. It also resolves symbolic link.
__CLASS__Signifies the function name exactly where it is used. When it is employed outside regarding any function, then it will return blank.
__DIR__This is the directory of a file.
__METHOD__This is method name of a class.

__NAMESPACE__Represents the name of the current namespace.


__FILE__  :  It represent the full path with file name 
<?php  
echo "The name of the file with path ". __FILE__;
?>  

__LINE__  :  It return the line line number from source file 
<?php  
echo "The name of the file with path" . __LINE__; // The name of the file with path 2
echo "The name of the file with path" . __LINE__; // The name of the file with path 3
echo "The name of the file with path" . __LINE__; // The name of the file with path 4
?>  

 __DIR__  :  It return only path for file

<?php  
 echo "The name of the file with path" . __DIR__; // The name of the file with path 2
// the directory of this file is: C:wampwww
?>  


__CLASS__  : 
 It return the class name

<?php  
class Newclass
{
    public function __construct() {
        echo __CLASS__;
    }
}
$obj = new Newclass(); // Sample
?>  


To know More Please see these Video :





Last Updated: 2018-07-06 12:32:44 By akshay

SHARE THIS

share_facebook share_twitter share_google_plus

Please Comment Here :