7evenline
7evenline

Reputation: 69

what is the difference between __FILE__ and $_SERVER['SCRIPT_FILENAME']?

define('QA_BASE_DIR', dirname(empty($_SERVER['SCRIPT_FILENAME']) ? __FILE__ : $_SERVER['SCRIPT_FILENAME']).'/');

what is the difference between __FILE__ and $_SERVER['SCRIPT_FILENAME'] ?

Upvotes: 2

Views: 2787

Answers (2)

David Ansermot
David Ansermot

Reputation: 6112

From the PHP documentation, the difference is that $_SERVER['SCRIPT_FILENAME'] contains the absolute path to the current script, and in CLI mode, may contains a relative path.

__FILE__ will contains you the path of included file if used inside an included file, or the path of main file if used inside the main file.

Upvotes: 3

Adrian Kaluzinski
Adrian Kaluzinski

Reputation: 83

Blackquoting from http://www.qualitycodes.com/tip/17/difference-between-serverscriptfilename-and-file.html:

$_SERVER['SCRIPT_FILENAME'] variable will return same path whether it is used in the main file or in an included file on the other hand __FILE__ variable will return you the path of included file if used inside an included file and the path of main file if used inside the main file. I am referring to main file the one whose name is displayed in the address bar of browser.

Upvotes: 1

Related Questions