Answers for "magic constant in php"

PHP
1

magic constant in php

<?php

echo "It will return current line number: ".__LINE__;
echo '<br>';
echo "It will return full path of file: ".__FILE__;
echo '<br>';
echo "It will return directory of executed file: ".__DIR__;
echo '<br>';
class Car
{
function demoMagic()
{
echo "It will return name of function where magic constant included: ".__FUNCTION__;
echo '<br>';
echo "It will return name of class where magic constant included: ".__CLASS__;

echo '<br>';
echo "It will return name of method with class where magic constant included: ".__METHOD__;
}
}
$obj = new Car();
$obj->demoMagic();

?>
Posted by: Guest on September-03-2021
0

magic constant in php

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.
__CLASS__	    The class name. The class name includes the namespace 
                it was declared in (e.g. Foo\Bar). 
__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.
Posted by: Guest on April-21-2021

Browse Popular Code Answers by Language