Obtaining the current file name

For some reason I just needed to get the name of the file I was currently in. So, here is a small function I cooked up which returns the name of the file you are in:

	 *	Returns the name of the file of execution
	 *	@param	bool	$baseFile 	If false, this function will return the name of the file this function resides in, if true, the current file of execution
	function getCurrentFileName($baseFile = false)
			return basename(__FILE__);
			return basename($_SERVER['SCRIPT_NAME']);

This function takes in a parameter (optional) which, if false, will take in to account whether or not the function will account for imports or not. Sometimes the function being called is not located in the file that’s being executed.

Leave a Reply