magic constant in php

Solutions on MaxInterview for magic constant in php by the best coders in the world

showing results for - "magic constant in php"
Mía
11 Sep 2017
1<?php
2
3echo "It will return current line number: ".__LINE__;
4echo '<br>';
5echo "It will return full path of file: ".__FILE__;
6echo '<br>';
7echo "It will return directory of executed file: ".__DIR__;
8echo '<br>';
9class Car
10{
11function demoMagic()
12{
13echo "It will return name of function where magic constant included: ".__FUNCTION__;
14echo '<br>';
15echo "It will return name of class where magic constant included: ".__CLASS__;
16
17echo '<br>';
18echo "It will return name of method with class where magic constant included: ".__METHOD__;
19}
20}
21$obj = new Car();
22$obj->demoMagic();
23
24?>
Kyle
25 Apr 2020
1Name	        Description
2__LINE__	    The current line number of the file.
3__FILE__	    The full path and filename of the file with symlinks 
4                resolved. If used inside an include, the name of the 
5                included file is returned.
6__DIR__	        The directory of the file. If used inside an include, 
7                the directory of the included file is returned. This is 
8                equivalent to dirname(__FILE__). This directory name 
9                does not have a trailing slash unless it is the root 
10                directory.
11__FUNCTION__	The function name.
12__CLASS__	    The class name. The class name includes the namespace 
13                it was declared in (e.g. Foo\Bar). 
14__TRAIT__	    The trait name. The trait name includes the namespace 
15                it was declared in (e.g. Foo\Bar).
16__METHOD__	    The class method name.
17__NAMESPACE__	The name of the current namespace.