02 Magic Constants 02 Magic Constants

02 — PHP Magic Constants

__LINE__

This returns the current line number of the file.

	
		//Example 1: __LINE__
		//For this example, we'll assume that this
		//statement is on the fifth line of a file.
		
		echo(__LINE__);
		//This statement returns "5".
	
	

__FILE__

This returns the full path and filename of the current file.

	
		//Example 2: __FILE__
		//For this example, we'll assume that this code is
		//somewhere inside of a file called "example.php" and that
		//the file "example.php" is in the root directory "httpdocs".

		echo(__FILE__);
		//This statement returns "httpdocs/example.php".
	
	

__DIR__

This returns the directory of the current file.

	
		//Example 3: __DIR__
		//For this example, we'll assume that this code is
		//somewhere inside of a file called "example.php" and that
		//the file "example.php" is in the root directory "httpdocs".

		echo(__DIR__);
		//This statement returns "httpdocs/".
	
	

__FUNCTION__

This returns the name of the current function. If the current function is an anonymous function, {closure} is returned instead.

	
		//Example 4: __FUNCTION__

		function exampleFunction()
		{
			echo(__FUNCTION__);
			//This statement returns "exampleFunction".
		}
	
	

Resources